【发布时间】:2020-08-16 03:29:50
【问题描述】:
示例 csv 如下所示:
name,id
row1,1
row2,2
row3,3
custom,test
custom,test2
row1,4
我为要检查重复项的每一行定义了一个字符串数组nameRows = ['row1', 'row2', 'row3']。如何仅在“名称”列下检查 nameRows 中的行是否重复?并忽略其他重复行,例如“自定义”。我只想要一个打印语句,上面写着 print('{0} is a duplicate row in the name column'.format(row))
半相关,我目前正在使用它来在 name 列下存在非常需要的行,也许我可以使用相同的 for 循环来查找错误...?
for row in nameRows:
if row not in df['name'].values:
print("Required {0} row 'name' not found in the csv file.".format(row))
【问题讨论】:
标签: python python-3.x pandas csv