Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # concatenate vertically two or more dataframes
- pd.concat([men2004, men2008], ignore_index = False, axis=0, keys = [2004,2008], names = 'Year')
- # add (sum indexes): aggregate/add the total number of Gold, Silver and Bronze Medals over both editions
- ath_2008.set_index("Athlete", inplace= True)
- ath_2012.set_index("Athlete", inplace= True)
- add = ath_2008.add(ath_2012, fill_value=0)
- add.head(10)
- # substract
- top1_df.sub(top2_df, fill_value = 0)
- # outer join
- olimpic1.merge(olimpic2, how = 'outer', on = 'Athlete', suffixes = ('_2005','_2020'), indicator = True)
- # inner join
- olimpic1.merge(olimpic2, how = 'inner', on = 'Athlete', suffixes = ('_2005','_2020'), indicator = True)
- # outer join without intersection
- combo_df = olimpic1.merge(olimpic2, how = 'outer', on = 'Athlete', suffixes = ('_2005','_2020'), indicator = True)
- combo_df.loc[combo_df._merge != 'both']
- # left join without intersection
- combo_df = olimpic1.merge(olimpic2, how = 'outer', on = 'Athlete', suffixes = ('_2005','_2020'), indicator = True)
- combo_df.loc[combo_df._merge == 'left_only']
- # right join without intersection
- combo_df = olimpic1.merge(olimpic2, how = 'outer', on = 'Athlete', suffixes = ('_2005','_2020'), indicator = True)
- combo_df.loc[combo_df._merge == 'right_only']
- # left join
- combo_df = olimpic1.merge(olimpic2, how = 'left', on = 'Athlete', suffixes = ('_2005','_2020'), indicator = True)
- # join on more than one column
- combo_df = olimpic1.merge(olimpic2, how = 'outer', on = ['Athlete', 'Medal'], suffixes = ('_2005','_2020'), indicator = True)
- combo_df = olimpic1.merge(olimpic2, how = 'inner', on = ['Athlete', 'Medal'], suffixes = ('_2005','_2020'), indicator = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement