I'm currently trying to count duplicate values in a CSV column of a file and return the value to another CSV column in python.
For example, my CSV file:
KeyID GeneralID
145258 KL456
145259 BG486
145260 HJ789
145261 KL456
What I want to achieve is to calculate how much data the same has GeneralIDand insert it into a new CSV column. For instance,
KeyID Total_GeneralID
145258 2
145259 1
145260 1
145261 2
I tried to split each column using the split method, but it did not work so well.
My code is:
case_id_list_data = []
with open(file_path_1, "rU") as g:
for line in g:
case_id_list_data.append(line.split('\t'))
source
share