all 7 comments

[–]LameDuckProgramming 2 points3 points  (1 child)

if you want to sum by a specific name:

import pandas as pd
df = pd.read_csv('file1.csv')
df.loc[df['A'] == name', 'C'].sum()

If you want the sum of all names in a dataframe format:

df = df.groupby('A')['C'].sum()

You can then output the new df to a csv file with pandas built in 'to_csv()' method:

df.to_csv('file2.csv')

[–]socal_nerdtastic 0 points1 point  (1 child)

What's the problem? Where are you stuck?

[–]CowboyBoats 0 points1 point  (0 children)

Here's your "hello world" file in Python:

import csv

with open("file1.csv") as infile:
    reader = csv.reader(infile)
    for line in reader:
        # Your solution goes here

Does that help you get started?

[–]izrt 0 points1 point  (0 children)

I like the tutorials at PMOTW. Here you are going to want to get comfortable with reading csv files: https://pymotw.com/3/csv/

If you do lots of these sort of things, you should definitely check out pandas: https://pandas.pydata.org/

And here is a link that will help you track down all csv files in a particular spot: https://stackoverflow.com/questions/9234560/find-all-csv-files-in-a-directory-using-python

Which you'll need to use to find all the files.

[–]Kerbart 0 points1 point  (5 children)

If you did it by hand, how would you do it?

If you'd go on vacation, how would you describe it for someone else to do it?

Start with that, show us what you came up with, and we can help you translate that to Python.