Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在 DataFrame 中恢复包含多个元素的组的行(按类型)。
TYPE VALEUR M1 A M1 B M2 A
结果应该是:
TYPE VALEUR M1 A M1 B
谢谢!
不知道优雅的解决方案。这是我的愚蠢:
In [149]: m = df.groupby('TYPE').size() > 1 In [151]: df[df['TYPE'].map(m)] Out[151]: TYPE VALEUR 0 M1 A 1 M1 B
ix如果您首先设置TYPE为索引,您也可以使用:
ix
TYPE
df.set_index("TYPE", inplace=True) df.ix[df.groupby(level=0).size() > 1]