【发布时间】:2020-08-28 00:28:15
【问题描述】:
我有一个非常大的 csv(或多或少 5000 万条记录)文件,其中包含不同的列,例如:
id, state, city, origin, destination, url, type
在这个文件中,我想检查每个重复的值,我的意思是所有具有完全相同列值的行,删除重复项,然后添加一个具有重复编号的新列。
例如,如果我有
id, state, city, origin, destination, url, type
1, NY, NY, manhattan, times square, http:ny.com, taxi
1, NY, NY, manhattan, times square, http:ny.com, taxi
1, NY, NY, manhattan, times square, http:ny.com, taxi
1, NY, NY, manhattan, times square, http:ny.com, taxi
我想输出这个
id, state, city, origin, destination, url, type, count
1, NY, NY, manhattan, times square, http:ny.com, taxi, 4
其中 count 是此列重复的次数。 我知道一些 javascript 但不知道 Python,但是我愿意使用任何工具,只要我可以使用新值和列创建一个新文件。
【问题讨论】:
-
用
pandas稍微研究一下,你会发现它适合你的ABC问题。 -
请show us你尝试了什么
-
@Tserenjamts 不要一看到 CSV 文件就盲目地使用 pandas。将其作为文本处理有时可能更简单......
-
@KooiInc 我没试过,因为我不知道从哪里开始 :)
-
@Tserenjamts 谢谢,我会看看我是否可以了解熊猫
标签: javascript python csv data-manipulation