2

Hy guys i have one problem with the python. I just start to learn and my teacher has give me the task with the python. So the problre is how i can calulate the sum from a column in csv file in pyhon.

Here is my tries :

import pandas as pd

df = pd.read_csv('1.csv')
dfsum=sum(df)

print(dfsum)

My termial is compley for i a do sum with str on integers.

Also the csv file is like this :

-12
-14
-76
-89
-98
-45
-26

1 Answer 1

1

So I dont know if your csv file contains only negative number or it's juste the way you present it, but what i can say is that you can try this it gonna work eitherway :
df = pd.read_csv("1.csv", names=["my_column"])
dfsum = df["my_column"].sum()

assuming you have all negative numbers the result is : -360

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.