Skip to content

Instantly share code, notes, and snippets.

Created June 17, 2019 07:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# Adding needed columns
bookDf['DateOrig'] = bookDf['Date']
bookDf['Day'] = bookDf['Date'].apply(lambda x:
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