Skip to content

Instantly share code, notes, and snippets.

@ken333135
Created June 17, 2019 07:56
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 ken333135/b14f4fe32fdd0bf06f6b77639c3f301c to your computer and use it in GitHub Desktop.
Save ken333135/b14f4fe32fdd0bf06f6b77639c3f301c to your computer and use it in GitHub Desktop.
# Adding needed columns
bookDf['DateOrig'] = bookDf['Date']
bookDf['Day'] = bookDf['Date'].apply(lambda x: x.day)
bookDf['Month'] = bookDf['Date'].apply(lambda x: dt.datetime.strftime(x,'%b'))
bookDf['DOW'] = bookDf['Date'].apply(lambda x: dt.datetime.strftime(x,'%a'))
bookDf['Month_num'] = bookDf['Date'].apply(lambda x: x.month)
bookDf['DOW_num'] = bookDf['Date'].apply(lambda x: x.weekday())
bookDf['Week_num'] = bookDf['Date'].apply(lambda x: int(dt.datetime.strftime(x,'%W')))
#add proxy for different colours
bookDf['color_proxy'] = bookDf[['Month_num','Title']].apply(lambda x: x[0] if str(x[1])!='nan' else 0,axis=1)
# columnmn for Y labels
bookDf['y_ticklabels'] = bookDf[['Day','Month']].apply(lambda x: x[1] if x[0]==1 else '',axis=1)
y_ticklabels = bookDf[['y_ticklabels','Week_num']].drop_duplicates()
y_withLabels = list(y_ticklabels[y_ticklabels['y_ticklabels']!='']['Week_num'])
y_ticklabels = y_ticklabels[(y_ticklabels['y_ticklabels']!='') | (y_ticklabels['Week_num'].apply(lambda x: int(x) not in list(y_withLabels)))]
y_ticklabels = list(y_ticklabels['y_ticklabels'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment