我将通过一列删除重复项,但是可以删除某些行。
有线连接的是:如果我直接读取2个文件而不是我的func1,func2,然后应用放置功能,那么一切都很好!
有没有人可以帮助您?谢谢!这是我的代码:
def func1(file):
df1 = pd.read_csv('balba')
"""select the col_name, then replace ' ' with ''
"""
return df1
def func2(file):
df2 = pd.read_csv('balba')
"""select the col_name, then replace ' ' with '', then rename the column name
"""
turn df2
df2 = func2(file_df2)
DF1 = []
for i in ['one_file_this_time']:
d = func1(i)
DF1.append(d)
df1 = pd.concat([DF1], sort=False)
df1.drop_duplicates(inplace=True)
df = pd.concat([df1, df2], sort=False)
print(df.shape)
# (7749, 2)
df.drop_duplicates(subset='col_name', inplace=True)
print(df.shape)
# (5082, 2)
"""obviously the drop_duplicates() functions works, but not fullly"""
您应该考虑在here中提到的drop_duplicates方法中添加keep参数。>
现在,您的代码符合以下原则:
非常相似第一个:删除第一个重复项之外的重复项。
没有重复的合并可能会为您提供帮助。这个问题与Pandas merge creates unwanted duplicate entries