简体   繁体   中英

How to sum a simple csv file column in python 3?

Beginner here, so sorry in advance for any stupid questions. I'm having trouble summing the column "Value" in the following simple csv file data set. Does anyone know how I could do this? I've included the code and output below:

Text:

import pandas as pd
file_name = "Roll_Data.csv"
pd.read_csv(file_name,delimiter='\t').dropna()

Output

Roll, Value

1     9.0
2     3.0
3     8.0
4     2.0

Choose "Value" series in your dataframe and call sum()

import pandas as pd

file_name = "Roll_Data.csv"
df = pd.read_csv(file_name,delimiter='\t').dropna()
df["Value"].sum()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM