how to sum a column in python csv

Solutions on MaxInterview for how to sum a column in python csv by the best coders in the world

showing results for - "how to sum a column in python csv"
Loukas
05 Apr 2016
1df["column_name"].sum()
Diego
18 May 2019
1import pandas as pd
2data = pd.read_csv('pandas.csv')
3df = pd.DataFrame(data)
4id_sum = 0
5data_sum = 0
6for i in range(len(df)):
7   if(i==len(df)-2 or i==len(df)-1):
8      id_sum = id_sum + df.iloc[i][0]
9      data_sum = data_sum + df.iloc[i][1]
10print("Id",id_sum)
11print("Data",data_sum)