xsv icon indicating copy to clipboard operation
xsv copied to clipboard

Adding rows together based on column value

Open margaretjoanmiller opened this issue 4 years ago • 2 comments

I have a CSV where data is split by county, month, and year. I'd like to add the rows in the county column based on month and year so that I have a row for each month (I essentially don't care about the county). Could you point me in the right direction?

margaretjoanmiller avatar Aug 07 '20 11:08 margaretjoanmiller

When asking questions, please always provide as much detail as possible. Otherwise, it's too difficult to help. In this case, please provide example inputs and outputs.

BurntSushi avatar Aug 07 '20 12:08 BurntSushi

Here is a row from the CSV

COUNTY          AGENCY NAME                       NCIC_AGENCY_CODE  MONTH  YEAR    OFFICERS_KILLED_FELONY OFFICERS_KILLED_ACCIDENT
Alameda County  Alameda Co. Sheriff's Department  100.0             1.0    2000.0  0.0                     0.0

I'd like the output to look like

 MONTH  YEAR    OFFICERS_KILLED_FELONY OFFICERS_KILLED_ACCIDENT
1.0    2000.0  0.0                     0.0

margaretjoanmiller avatar Aug 07 '20 12:08 margaretjoanmiller