Skip to content

Instantly share code, notes, and snippets.

@anbento0490
Last active May 2, 2020 09:06
Show Gist options
  • Save anbento0490/62df7699aa7a21766be60ebddd694c30 to your computer and use it in GitHub Desktop.
Save anbento0490/62df7699aa7a21766be60ebddd694c30 to your computer and use it in GitHub Desktop.
#1. ROW NUMBER() --> .RANK(method='first')
# Ranks orders over time by Custoner ID
orders['Row Num'] = orders.groupby(['Customer ID'])['Order Date'].rank(method='first')
# Sorts values by Customer ID and Order Date in ascending order
orders.sort_values(by= ['Customer ID','Order Date'], inplace = True)
orders = orders.reset_index(drop = True)
orders.head(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment