Skip to content

Instantly share code, notes, and snippets.

@mahpah
Last active August 18, 2020 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahpah/d201287950b27810d8eac8fc9191da4b to your computer and use it in GitHub Desktop.
Save mahpah/d201287950b27810d8eac8fc9191da4b to your computer and use it in GitHub Desktop.
compare using pandas
path = r'/home/mahpah/repo/labs/python/data/input.xlsx'
data = pd.read_excel(path)
data = data.sort_values(by = ['ID', 'Ngay'])
data.loc[data['No qua han'].eq(data['No qua han'].shift()), 'match'] = 'no change'
data.loc[data['No qua han'].lt(data['No qua han'].shift()), 'match'] = 'A'
data.loc[data['No qua han'].gt(data['No qua han'].shift()), 'match'] = 'B'
data.loc[data['ID'].ne(data['ID'].shift()), 'match'] = ''
print(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment