1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
df.name.isnull().any()
movies_gb_rating = movies.groupby('rating')
movies_gb_rating.ngroups
movies_gb_rating.groups
>> results -> 'G': [107, 933, 1126, 1557, 2911, 3059, ], 'NC-17': [5264, 6338, 7263], 'NR': [5971, 5987, 6015, 6054, 6087, 6093, 6095, 6179, 6190, 6207, 6208, 6226], 'PG': [6, 41, 42, 43, 45, 94, 115, 127, 137, 155, 156, 167, 168, 231, 300, 325, 326, 330, 344, 345, 347, 393, ...], 'PG-13': [0, 9, 27, 28, 29, 38, 44, 88, 112, 117, 128, 129, 134, 138, 142, , ...],
movies_gb_rating.first()
movies_gb_rating.get_group('G')
for name, group in movies_gb_rating: print(name) print('--------') print(group)
grouped_df = df.groupby('student').grade.mean() grouped_df = df.groupby('student', as_index=False).grade.mean()
df.groupby('column1').column2.measurement() pricey_shoes = orders.groupby("shoe_type").price.max()
df = books.groupby('Genre')['Price'].max().reset_index() df >> Genre Price 0 Fiction 82 1 Non Fiction 105
output.rename(columns = {"Price": "Max_price"}, inplace = True)
df >> Genre Max_price 0 Fiction 82 1 Non Fiction 105
@sort_values() books.fillna(0).groupby('Year').agg({'Author':'count', 'Price':['max', 'mean']})\ .rename(columns={"count":'num_of_authers', "sum":'max_price',"mean":'avg_price'})\ .sort_values(by=[('Author', 'num_of_authers'), ('Price', 'avg_price')], ascending=[False, True]) >> result -> Author Price num_of_authers max_price avg_price Year 2019 50 27 10.08 2015 50 46 10.42 2018 50 46 10.52
|