Articles → Pandas → Groupby Function In Pandas
Groupby Function In Pandas
Purpose
Example
import numpy as np
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)
# Group By
print("Group By\n")
df.groupby("company").sum()
Output
Click to Enlarge