Youtube Video commentary is also available.
P-030: For the receipt detail data frame (df_receipt), calculate the sample variance of the sales amount (amount) for each store code (store_cd), and display the TOP5 in descending order.
code
df_receipt.groupby('store_cd').amount.var(ddof=0).reset_index().sort_values('amount', ascending=False).head(5)
store_cd | amount | |
---|---|---|
28 | S13052 | 440088.7013 |
31 | S14011 | 306314.5582 |
42 | S14034 | 296920.081 |
5 | S13001 | 295431.9933 |
12 | S13015 | 295294.3611 |
-Pandas DataFrame / Series.
-Use this when you want to process data with the same value together and check the total or average of the data with the same value.
-'Groupby' is used when you want to collect data with the same value or character string and perform common operations (total, average, etc.) on each same value or character string.
-**'.Var' is the code to calculate the sample variance **.
· '
code
df_receipt.groupby('store_cd').agg({'amount':'var'}).reset_index().sort_values('amount', ascending=False).head(5)
Recommended Posts