This file contains 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
import pandas as pd | |
import datetime as dt | |
booksv2 = pd.read_csv('book1.csv') | |
booksv2['Start'] = booksv2['Start'].apply(lambda x: dt.datetime.strptime(str(x),'%d/%m/%Y')) | |
booksv2['End'] = booksv2['End'].apply(lambda x: dt.datetime.strptime(str(x),'%d/%m/%Y')) | |
min_date = min(list(booksv2['Start'])+list(booksv2['End'])) | |
max_date = max(list(booksv2['Start'])+list(booksv2['End'])) | |
#year = min_date.year |
This file contains 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
def date_generator(from_date,to_date): | |
while from_date<=to_date: | |
yield from_date | |
from_date = from_date + dt.timedelta(days=1) | |
# create a new df with 2 columns | |
# col1 : Title, col2: DateRead | |
Title = [] | |
Date = [] | |
for index,row in booksv2.iterrows(): |
This file contains 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
# create a df with date from 1st to last day of year from min_year | |
dateList = pd.DataFrame(list(date_generator(dt.datetime(year,1,1,0,0,0),dt.datetime(year,12,31,0,0,0))),columns=['Date']) | |
dateList.Date = dateList.Date.astype('O') |
This file contains 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
# 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 |
This file contains 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
# set colors | |
cmap=['white','red','orange','yellow','green','blue', | |
'indigo','violet','purple','grey','pink', | |
'brown','black'] | |
f, ax = plt.subplots(figsize=(6, 18)) | |
# drop duplicates for bookDf **End of book A is the start of book B | |
df = bookDf.copy() | |
df.drop_duplicates(['Date'],inplace=True) |
OlderNewer