# This 'str' operation splits each candidiate's full name at each
# blank space, then takes just the candidiate's first name
elections["First Name"] = elections["Candiate"].str.split().str[0]
elections.head(5)
# Here, we'll only consider `babynames` data from 2020
babynames_2020 = babynames[babynames["Year"]==2020]
babynames_2020.head()
Now, ready to join two tables.
pd.merge()
merged = pdmerge(left = elections, right = babynames_2020, \
left_on = "First Name", right_on = "Name")
merged.head()
# Notice that pandas automatically specifies 'Year_x' and 'Year_y'
# when both merged DataFrames have the same column name to avoid confusion
'Computer Science 🌋 > Machine Learning🐼' 카테고리의 다른 글
CSV files and field names (0) | 2023.05.24 |
---|---|
Data Cleaning Structure (0) | 2023.05.24 |
Aggregation Data with Pivot Table in Pandas (0) | 2023.05.23 |
Aggregation in Pandas (0) | 2023.05.23 |
Aggregating Data with GroupBy in Pandas (0) | 2023.05.23 |