Python 获取多个列的唯一值,将其作为新的数据帧显示在pandas中
拥有至少包含C1、C2、C3列的熊猫数据帧df,如何将所有唯一的C1、C2、C3值作为新的数据帧 换句话说,类似于:Python 获取多个列的唯一值,将其作为新的数据帧显示在pandas中,python,pandas,pandas-groupby,Python,Pandas,Pandas Groupby,拥有至少包含C1、C2、C3列的熊猫数据帧df,如何将所有唯一的C1、C2、C3值作为新的数据帧 换句话说,类似于: SELECT C1,C2,C3 FROM T GROUP BY C1,C2,C3 试过了 print df.groupby(by=['C1','C2','C3']) 但是我越来越 <pandas.core.groupby.DataFrameGroupBy object at 0x000000000769A9E8> 我相信,如果想要所有独特的三元组,您需要: df
SELECT C1,C2,C3
FROM T
GROUP BY C1,C2,C3
试过了
print df.groupby(by=['C1','C2','C3'])
但是我越来越
<pandas.core.groupby.DataFrameGroupBy object at 0x000000000769A9E8>
我相信,如果想要所有独特的三元组,您需要:
df = df.drop_duplicates(subset=['C1','C2','C3'])
如果要使用groupby add:
df = df.groupby(by=['C1','C2','C3'], as_index=False).first()