考虑这个简单的数据框:
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
为什么pandas每次都会打印出垃圾?
我已经验证了这在v0.20中发生。
编辑:寻找答案,而不是解决方法。
df.apply(lambda x: [x])
相同。 - DYZdf1=pd.DataFrame({'a':[1],'b':[2]})
df1.apply(lambda x: [x],axis=1)
输出:0 [[0, 0]]
。 - DYZapply
弄坏了...现在你需要修复它! - piRSquared0.21.0.dev+
主分支上的行为。 - Zero