熊猫删除计数后重复保存CSV

时间:2018-07-04 14:54:01

标签: python python-3.x pandas

我试图使用以下命令从csv文件中删除重复出现的内容并将其保存为原样:

out.groupby(out.columns.tolist(),as_index=False).size().to_csv("happy.csv")

但是在输出文件中,我看到了最后附有,(逗号)的行的行数,如下所示:

0.0,0-1,-40.573689825284745,-40--39,46.29786832672374,46-47,-27.683943467097148,-27--26,-46.29786832672374,0,1,-48.149567703555356,-43--42,-48.149567703555356,-49--48,Red,3
0.0,0-1,-40.573689825284745,-40--39,46.29786832672374,46-47,-27.683943467097148,-27--26,-46.29786832672374,0,1,-47.736599665518064,-44--43,-47.736599665518064,-48--47,Red,2
0.0,0-1,-40.573689825284745,-40--39,46.29786832672374,46-47,-27.683943467097148,-27--26,-46.29786832672374,0,1,-47.2872876816451,-45--44,-47.2872876816451,-48--47,Red,3
0.0,0-1,-40.573689825284745,-40--39,46.29786832672374,46-47,-27.683943467097148,-27--26,-46.29786832672374,0,1,-46.801965565667714,-45--44,-46.801965565667714,-47--46,Red,3
0.0,0-1,-40.573689825284745,-40--39,46.29786832672374,46-47,-27.683943467097148,-27--26,-46.29786832672374,0,1,-46.280989309334466,-46--45,-46.280989309334466,-47--46,Red,1

我要保存文件,而新的csv中该行没有计数。

输出必须如下所示:

0.0,0-1,-40.573689825284745,-40--39,46.29786832672374,46-47,-27.683943467097148,-27--26,-46.29786832672374,0,1,-48.149567703555356,-43--42,-48.149567703555356,-49--48,Red
0.0,0-1,-40.573689825284745,-40--39,46.29786832672374,46-47,-27.683943467097148,-27--26,-46.29786832672374,0,1,-47.736599665518064,-44--43,-47.736599665518064,-48--47,Red
0.0,0-1,-40.573689825284745,-40--39,46.29786832672374,46-47,-27.683943467097148,-27--26,-46.29786832672374,0,1,-47.2872876816451,-45--44,-47.2872876816451,-48--47,Red
0.0,0-1,-40.573689825284745,-40--39,46.29786832672374,46-47,-27.683943467097148,-27--26,-46.29786832672374,0,1,-46.801965565667714,-45--44,-46.801965565667714,-47--46,Red
0.0,0-1,-40.573689825284745,-40--39,46.29786832672374,46-47,-27.683943467097148,-27--26,-46.29786832672374,0,1,-46.280989309334466,-46--45,-46.280989309334466,-47--46,Red  

请指导我如何实现这一目标?

0 个答案:

没有答案