#Coded by Andrew
#Youtube does not allow angled brackets in video titles or descriptions so I replaced it with actual text. You will need to replace it back to original code in the video to execute.
import pandas as pd
import numpy as np
ipl_data = {'Team': ['Riders', 'Riders', 'Devils', 'Devils', 'Kings',
'Kings', 'Kings', 'Kings', 'Riders', 'Royals', 'Royals', 'Kings'],
'Rank': [1, 2, 2, 7, 3,4 ,1 ,1,2 , 4,1,2],
'Year': [2014,2015,2014,2015,2014,2015,2016,2017,2016,2014,2015,2017],
'Points':[876,789,863,673,741,812,756,999,694,701,804,690]}
df = pd.DataFrame(ipl_data)
print('Example 1')
print (df.groupby('Team').filter(lambda x: len(x) ‘greater than’= 4).sort_values(by=['Team','Rank','Year','Points']),'\n')
print('Example 2')
print (df.groupby('Team').filter(lambda x: x['Points'].mean() ‘greater than’ df['Points'].agg([np.mean])).sort_values(by=['Team','Rank','Year','Points']))
Watch video Python Bytes - Panda Dataframe Groupby Filter online without registration, duration hours minute second in high quality. This video was added by user AC 13 May 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 777 once and liked it 5 people.