Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.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
Pandas 如何从只留下一个实例的数据帧中删除特定的重复列_Pandas - Fatal编程技术网

Pandas 如何从只留下一个实例的数据帧中删除特定的重复列

Pandas 如何从只留下一个实例的数据帧中删除特定的重复列,pandas,Pandas,我知道上面提到的可能是一个简单的任务,但它已经花了我很多小时没有任何成功。到目前为止,我在网上搜索也没有成功。因此,我有以下数据帧: 并且,我正在寻找以下预期结果: 我使用了以下代码行: # drop repeat columns leaving the first instance only: df_combo = df_combo.drop_duplicates(['Asgn Carr Cd','Fiscal Month'], keep='first') 然而,这并没有达到我想要的结

我知道上面提到的可能是一个简单的任务,但它已经花了我很多小时没有任何成功。到目前为止,我在网上搜索也没有成功。因此,我有以下数据帧:

并且,我正在寻找以下预期结果:

我使用了以下代码行:

# drop repeat columns leaving the first instance only:
 df_combo = df_combo.drop_duplicates(['Asgn Carr Cd','Fiscal Month'], keep='first')

然而,这并没有达到我想要的结果。提前感谢您的帮助/建议a。

请先查看
groupby

df.groupby(level=0,axis=1).first()

可以使用
np.unique
为每个唯一列名获取一个索引,然后切片:

import numpy as np

df.iloc[:, np.unique(df.columns, return_index=True)[1]]

始终建议在您的帖子中以文本格式发布您的示例,而不是在图像/链接/或其他一些网站中发布。这将使试图提供帮助的人的生活变得轻松,请编辑您的帖子,然后让我们知道。