Articles → Pandas → Use Sum Function For A Column In Dataframe In Pandas

Use Sum Function For A Column In Dataframe In Pandas






Example


import pandas as pd


# Create a dictionary
dict = {
    "company": ["Google", "Microsoft", "Apple", "Google", "Microsoft", "Apple"],
    "year": [2017, 2017, 2017, 2018, 2018, 2018],
    "Profit": [20000, 40000, 60000, 80000, 70000, 50000],
}

# Create a dataframe
df = pd.DataFrame(dict)

# Find Sum of all profits

print(df["Profit"].sum())



Output


Picture showing the output of sum function for a column in dataframe in pandas
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, May 15, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250