I have a csv file with thousands of entries that need to be broken up into groups. In the example below, I need each row broken up into groups based on the River Name so later I can reformat the information based on their groups.
River Name, Branch, Length
Catnip, 1, 2145.30
Peterson, 2, 24.5
Catnip, 3, 15.4
Fergerson, 1, 5.2
Catnip, 1, 88.56
Peterson, 2, 6.45
The only way I can think of grouping the information would be to:
- Use python to read csv and create a list of just the unique river names.
- Create new individual csv based on the unique river names e.g Peterson.csv, Catnip.csv.
- Use python to read the original csv, and depending on the river name on the row being read, write that row to the corresponding .csv file. e.g row Catnip, 1, 2145.30 would be written to catnip.csv
I don't think this is an efferent way to go about this as it gives me about 1500 csv that will need to be open and written to, but I am at my limits of python knowledge. If any one could provide a better methodology, it would greatly be appreciated.