Course Notes
Use this workspace to take notes, store code snippets, and build your own interactive cheatsheet!
# Import any packages you want to use here
Take Notes
Add notes here about the concepts you've learned and code cells with code you want to keep.
Joining data with pandas
Add your code snippets here
#Inner Join Pandas
wards_census = wards.merge(census, on='ward') print(wards_census.head(4))
After adding Suffixes to the columns of joining tables
wards_census = wards.merge(census, on='ward', suffixes=('_ward','_cen'))
Multiple columns Merge
grants.merge(licenses, on=['address','zip'])
Merging Multiple tables
grants_licenses_ward = grants.merge(licenses, on=['address','zip'])
.merge(wards, on='ward', suffixes=('_bus','_ward'))
Threetables:
df1.merge(df2, on='col') \ .merge(df3, on='col')
Fourtables:
df1.merge(df2, on='col') \ .merge(df3, on='col') \ .merge(df4, on='col')
Merging Tables With Different Join Types
movies_taglines = movies.merge(taglines, on='id', how='left')
tv_movies = movies.merge(tv_genre, how='right',left_on='id', right_on='movie_id')
family_comedy = family.merge(comedy, on='movie_id', how='outer',suffixes=('_fam', '_com'))
original_sequels = sequels.merge(sequels, left_on='sequel', right_on='id',suffixes=('_org','_seq'))
movies_genres = movies.merge(movie_to_genres, left_on='id', left_index=True, right_on='movie_id', right_index=True)
Filtering joins