我正在使用pandas列出当前csv中的所有重复值。我可以将它打印到控制台,但我想将其写入带有标题的csv,以便将所有数据分类到列和行中。目前,使用写入输出将其转储到一列中。
try:
ufo = pd.read_csv('missdata.csv')
dup = ufo.loc[ufo.Usage.duplicated(keep = False), :]
print(dup)
output = open('outputdata.csv', 'w')
output.write(str(ufo.loc[ufo.Usage.duplicated(), :]))
控制台输出
LocationID Name Usage EquipmentExtRef
1 125 Manchester Exchange 0.0 VirtMeter_Main
3 125 Manchester Exchange 0.0 VirtMeter_Main
4 125 Manchester Exchange 0.0 VirtMeter_Main
6 125 Manchester Exchange 608.4 VirtMeter_Main
7 125 Manchester Exchange 577.8 VirtMeter_Main
8 125 Manchester Exchange 550.3 VirtMeter_Main
9 125 Manchester Exchange 617.3 VirtMeter_Main
10 125 Manchester Exchange 629.4 VirtMeter_Main
11 125 Manchester Exchange 712.3 VirtMeter_Main