Created
October 19, 2020 08:06
-
-
Save manmohan24nov/995ca68c04a0053a72d1179e563e0cb7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| In [3]: weekly_sales_df = sales_data[['Store', | |
| ...: 'Date', | |
| ...: 'Weekly_Sales']].groupby(['Date', | |
| ...: 'Store']).agg({'Weekly_Sales':'sum'}) | |
| In [4]: weekly_sales_df.reset_index(inplace=True) | |
| In [5]: weekly_sales_df['rank']=weekly_sales_df.groupby(['Store'])['Weekly_Sales'].rank(ascending=False) | |
| ...: weekly_sales_df['dense_rank'] = weekly_sales_df.groupby(['Store'])['Weekly_Sales'].rank(method='dense', | |
| ...: ascending=False) | |
| In [6]: weekly_sales_df[weekly_sales_df['Store']==5].sort_values(by='rank') | |
| Out[6]: | |
| Date Store Weekly_Sales rank dense_rank | |
| 5269 25/11/2011 5 507900.07 1.0 1.0 | |
| 5494 26/11/2010 5 488362.61 2.0 2.0 | |
| 5044 24/12/2010 5 466010.25 3.0 3.0 | |
| 4819 23/12/2011 5 458562.24 4.0 4.0 | |
| 1129 06/04/2012 5 402985.70 5.0 5.0 | |
| ... ... ... ... ... ... | |
| 4729 23/07/2010 5 274742.63 139.0 139.0 | |
| 5359 26/03/2010 5 273282.97 140.0 140.0 | |
| 5314 26/02/2010 5 270281.63 141.0 141.0 | |
| 6214 30/07/2010 5 270281.63 141.0 141.0 | |
| 2794 14/01/2011 5 260636.71 143.0 142.0 | |
| [143 rows x 5 columns] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment