我一辈子都搞不懂为什么filter方法拒绝对pandas中的数据帧起作用。在
下面是一个显示我的问题的示例:
In [99]: dff4
Out[99]: <pandas.core.groupby.DataFrameGroupBy object at 0x1143cbf90>
In [100]: dff3
Out[100]: <pandas.core.groupby.DataFrameGroupBy object at 0x11439a810>
In [101]: dff3.groups
Out[101]:
{'iphone': [85373, 85374],
'remote_api_created': [85363,
85364,
85365,
85412]}
In [102]: dff4.groups
Out[102]: {'bye': [3], 'bye bye': [4], 'hello': [0, 1, 2]}
In [103]: dff4.filter(lambda x: len(x) >2)
Out[103]:
A B
0 0 hello
1 1 hello
2 2 hello
In [104]: dff3.filter(lambda x: len(x) >2)
Out[104]:
Empty DataFrame
Columns: [source]
Index: []
注意filter如何拒绝在dff3上工作。在
感谢任何帮助。在
如果按列名分组,则将其移动到索引,这样数据帧将变为空;如果没有其他列,请参阅:
可以按列值分组:
^{pr2}$相关问题 更多 >
编程相关推荐