为什么pandas.DataFrame.apply打印出垃圾? [英] Why is pandas.DataFrame.apply printing out junk?
本文介绍了为什么pandas.DataFrame.apply打印出垃圾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下简单数据框:
a b
0 1 2
1 2 3
我这样执行.apply
:
In [4]: df.apply(lambda x: [x.values])
Out[4]:
a [[140279910807944, 140279910807920]]
b [[140279910807944, 140279910807920]]
dtype: object
In [5]: df.apply(lambda x: [x.values])
Out[5]:
a [[37, 37]]
b [[37, 37]]
dtype: object
In [6]: df.apply(lambda x: [x.values])
Out[6]:
a [[11, 11]]
b [[11, 11]]
dtype: object
为什么熊猫每次都会打印出垃圾?
Why is pandas printing out junk each time?
我已经验证了这种情况发生在v0.20中.
I've verified this happens in v0.20.
寻找答案,而不是解决方法.
Looking for an answer, not a workaround.
推荐答案
它看起来像bug,因此已打开问题17487 .
It looks like bug, so was opened Issue 17487.
对我来说,添加tolist
:
print (df.apply(lambda x: [x.values.tolist()]))
a [[1, 2]]
b [[2, 3]]
dtype: object
print (df.apply(lambda x: [list(x.values)]))
a [[1, 2]]
b [[2, 3]]
dtype: object
这篇关于为什么pandas.DataFrame.apply打印出垃圾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文