为什么 pandas.DataFrame.apply 打印出垃圾? [英] Why is pandas.DataFrame.apply printing out junk?
本文介绍了为什么 pandas.DataFrame.apply 打印出垃圾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑这个简单的数据框:
Consider this simple dataframe:
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屋!
查看全文