Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取多个列的唯一值,将其作为新的数据帧显示在pandas中_Python_Pandas_Pandas Groupby - Fatal编程技术网

Python 获取多个列的唯一值,将其作为新的数据帧显示在pandas中

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

拥有至少包含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 = df.drop_duplicates(subset=['C1','C2','C3'])
如果要使用groupby add:

df = df.groupby(by=['C1','C2','C3'], as_index=False).first()