# Find the total number of baby names associated with each sex for each year in the data
babynames.groupby(["Year", "Sex"])[["Count"]].agg(sum).head(6)
# The 'Pivot_table' method is used to generate a Pandas pivot table
import numpy as np
babynames.pivot_table(index = "Year", columns = "Sex", values = "Count", aggfunc = np.sum).head(5)
# This includes multiple values in the index or columns of our pivot tables
babynames_pivot = babynames.pivot_table(
index="Year",
columns="Sex",
values=["Count", "Name"],
aggfunc=max,
)
babynames_pivot.head(6)
'Computer Science 🌋 > Machine Learning🐼' 카테고리의 다른 글
Data Cleaning Structure (0) | 2023.05.24 |
---|---|
Joining Tables (0) | 2023.05.23 |
Aggregation in Pandas (0) | 2023.05.23 |
Aggregating Data with GroupBy in Pandas (0) | 2023.05.23 |
Add & Remove Columns (0) | 2023.05.23 |