【发布时间】:2020-03-26 20:32:54
【问题描述】:
我将删除其中一列的重复项,但可以删除某些行。
连线的事情是:如果我直接读取 2 个文件而不是通过我的 func1、func2,然后应用 drop 函数,一切都很好!
更新1: 非常喜欢 unicode 问题(感谢 furkanayd),如何解决?
有人可以帮忙吗?谢谢!这是我的代码:
def func1(file):
try:
df1 = pd.read_csv('balba', encoding='utf8', low_memory=False)
except UnicodeDecodeError:
df1 = pd.read_csv('balba', encoding='gb18030', low_memory=False)
"""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)
print(df.duplicated().any())
# (5082, 2)
# False
"""obviously the drop_duplicates() functions works, but not fullly"""
【问题讨论】:
-
发布一些数据..会有所帮助
-
很难描述您的问题。向我们展示您的一些数据样本。
标签: python pandas subset drop-duplicates