book-tracking-2019-07


2019 Book Update


In [1]:
import pandas as pd
import numpy as np

Read in my Goodreads Export


In [2]:
book_df = pd.read_csv('goodreads_library_export.csv')
book_df['Date Added'] = pd.to_datetime(book_df['Date Added'],
                                       format="%Y/%m/%d")

In [3]:
book_df.columns


Out[3]:
Index(['Book Id', 'Title', 'Author', 'Author l-f', 'Additional Authors',
       'ISBN', 'ISBN13', 'My Rating', 'Average Rating', 'Publisher', 'Binding',
       'Number of Pages', 'Year Published', 'Original Publication Year',
       'Date Read', 'Date Added', 'Bookshelves', 'Bookshelves with positions',
       'Exclusive Shelf', 'My Review', 'Spoiler', 'Private Notes',
       'Read Count', 'Recommended For', 'Recommended By', 'Owned Copies',
       'Original Purchase Date', 'Original Purchase Location', 'Condition',
       'Condition Description', 'BCID'],
      dtype='object')

Select the books from the goodreads dump

  • Get relevant columns
  • Sort by newest
  • Remove unsightly NaNs,
  • Filter to only 'read' books and then get rid of filter column
  • Only books added to Goodreads in 2019

In [4]:
cols = ['Title', 'Author', 'Date Added', 'Number of Pages',
        'My Rating', 'Exclusive Shelf']
export_df = (
                 book_df[cols]
                 .sort_values('Date Added', ascending=False)
                 .fillna('')
                 [book_df['Exclusive Shelf'] == "read"]
                 [book_df['Date Added'] > pd.datetime(2019, 1, 1)]
                 .drop('Exclusive Shelf', axis=1)
            )
export_df.loc[14, 'Number of Pages'] = 576.0  # Not in the GR db, apparently
export_df


/Users/dannowitz/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:7: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
  import sys
/Users/dannowitz/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:8: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
  
Out[4]:
Title Author Date Added Number of Pages My Rating
1 Norse Mythology Neil Gaiman 2019-07-26 301 3
2 Reamde Neal Stephenson 2019-07-13 1044 3
3 The Running Man Richard Bachman 2019-07-09 317 4
4 A Little History of Philosophy Nigel Warburton 2019-07-08 252 5
5 Superforecasting: The Art and Science of Predi... Philip E. Tetlock 2019-07-05 352 5
6 A Natural History of Dragons (The Memoirs of L... Marie Brennan 2019-07-02 334 3
7 The Woman in the Window A.J. Finn 2019-07-02 449 5
8 The Outsider Stephen King 2019-06-25 561 3
10 Exhalation: Stories Ted Chiang 2019-06-25 352 5
12 All Gifts, Bestowed: An Artificial Intelligenc... Joshua Gayou 2019-06-23 428 3
9 Recursion Blake Crouch 2019-06-12 329 4
13 Fall, or Dodge in Hell Neal Stephenson 2019-06-11 896 3
11 The Player of Games (Culture, #2) Iain M. Banks 2019-06-01 293 4
14 Children of Ruin (Children of Time #2) Adrian Tchaikovsky 2019-05-31 576 5
15 Revival Stephen King 2019-05-31 405 3
16 A Gentleman in Moscow Amor Towles 2019-05-28 496 5
19 The Graveyard Book Neil Gaiman 2019-05-21 307 4
17 The Power Naomi Alderman 2019-05-21 341 5
18 Spinning Silver Naomi Novik 2019-05-20 480 4
20 The Lathe of Heaven Ursula K. Le Guin 2019-05-20 176 5
21 Six Wakes Mur Lafferty 2019-05-20 364 5
22 The Dead Zone Stephen King 2019-05-20 402 4
23 Dune (Dune Chronicles, #1) Frank Herbert 2019-04-24 687 4
24 The Incomplete Book of Running Peter Sagal 2019-04-24 197 5
25 Lost Gods Brom 2019-04-24 496 5
26 All Clear (All Clear, #2) Connie Willis 2019-04-24 656 3
27 Blackout (All Clear, #1) Connie Willis 2019-03-14 610 2
28 A Man Called Ove Fredrik Backman 2019-03-14 337 3
29 A Canticle for Leibowitz (St. Leibowitz, #1) Walter M. Miller Jr. 2019-03-12 334 5
30 The Age of Agile: How Smart Companies Are Tran... Stephen Denning 2019-03-08 336 5
31 The Curious Incident of the Dog in the Night-Time Mark Haddon 2019-03-08 226 4
34 Elevation Stephen King 2019-03-08 146 5
33 Less Andrew Sean Greer 2019-03-08 273 4
35 Where'd You Go, Bernadette Maria Semple 2019-02-14 330 5
32 Cryptonomicon Neal Stephenson 2019-02-14 1139 3
36 The Cuckoo's Calling (Cormoran Strike, #1) Robert Galbraith 2019-02-11 455 4
38 Full Dark, No Stars Stephen King 2019-01-27 368 5
43 Mr. Penumbra's 24-Hour Bookstore (Mr. Penumbra... Robin Sloan 2019-01-23 288 4
37 Finding Ultra, Revised and Updated Edition: Re... Rich Roll 2019-01-23 400 2
40 Origin (Robert Langdon, #5) Dan Brown 2019-01-23 461 4
41 Lincoln in the Bardo George Saunders 2019-01-23 343 4
42 The Rise and Fall of D.O.D.O. Neal Stephenson 2019-01-23 752 5
45 The Endless Knot (The Song of Albion, #3) Stephen R. Lawhead 2019-01-23 439 3
46 Pet Sematary Stephen King 2019-01-23 580 5

Everyone loves star ratings


In [13]:
def ratings_to_stars(rating):
    return ("★" * rating +
            "✩" * (5-rating))

In [14]:
export_df['My Rating'] = export_df['My Rating'].apply(ratings_to_stars)

In [15]:
export_df.head()


Out[15]:
Title Author Date Added Number of Pages My Rating
1 Norse Mythology Neil Gaiman 2019-07-26 301 ★★★✩✩
2 Reamde Neal Stephenson 2019-07-13 1044 ★★★✩✩
3 The Running Man Richard Bachman 2019-07-09 317 ★★★★✩
4 A Little History of Philosophy Nigel Warburton 2019-07-08 252 ★★★★★
5 Superforecasting: The Art and Science of Predi... Philip E. Tetlock 2019-07-05 352 ★★★★★

Create the style for display


In [19]:
# Define hover behavior
hover_props = [("background-color", "#CCC")]

# Set CSS properties for th elements in dataframe
th_props = [
  ('font-size', '13px'),
  ('text-align', 'left'),
  ('font-weight', 'bold'),
  ('color', '#6d6d6d'),
  ('background-color', '#f7f7f9'),
  ]

# Set CSS properties for td elements in dataframe
td_props = [
  ('font-size', '12px'),
  ('padding', '0.75em 0.75em'),
  ('max-width', "250px")
  ]

# Set table styles
styles = [
  dict(selector="tr:hover", props=hover_props),
  dict(selector="th", props=th_props),
  dict(selector="td", props=td_props)
  ]

style_df = (
    export_df
    .reset_index(drop=True)
    .style
    .set_table_styles(styles)
    .bar(subset=['Number of Pages'], color='#999')
    .format({"Date Added": lambda x: x.strftime(format="%Y-%m-%d")})
    .format({"Number of Pages": lambda x: int(x)})
)

style_df


Out[19]:
Title Author Date Added Number of Pages My Rating
0 Norse Mythology Neil Gaiman 2019-07-26 301 ★★★✩✩
1 Reamde Neal Stephenson 2019-07-13 1044 ★★★✩✩
2 The Running Man Richard Bachman 2019-07-09 317 ★★★★✩
3 A Little History of Philosophy Nigel Warburton 2019-07-08 252 ★★★★★
4 Superforecasting: The Art and Science of Prediction Philip E. Tetlock 2019-07-05 352 ★★★★★
5 A Natural History of Dragons (The Memoirs of Lady Trent, #1) Marie Brennan 2019-07-02 334 ★★★✩✩
6 The Woman in the Window A.J. Finn 2019-07-02 449 ★★★★★
7 The Outsider Stephen King 2019-06-25 561 ★★★✩✩
8 Exhalation: Stories Ted Chiang 2019-06-25 352 ★★★★★
9 All Gifts, Bestowed: An Artificial Intelligence Thriller Joshua Gayou 2019-06-23 428 ★★★✩✩
10 Recursion Blake Crouch 2019-06-12 329 ★★★★✩
11 Fall, or Dodge in Hell Neal Stephenson 2019-06-11 896 ★★★✩✩
12 The Player of Games (Culture, #2) Iain M. Banks 2019-06-01 293 ★★★★✩
13 Children of Ruin (Children of Time #2) Adrian Tchaikovsky 2019-05-31 576 ★★★★★
14 Revival Stephen King 2019-05-31 405 ★★★✩✩
15 A Gentleman in Moscow Amor Towles 2019-05-28 496 ★★★★★
16 The Graveyard Book Neil Gaiman 2019-05-21 307 ★★★★✩
17 The Power Naomi Alderman 2019-05-21 341 ★★★★★
18 Spinning Silver Naomi Novik 2019-05-20 480 ★★★★✩
19 The Lathe of Heaven Ursula K. Le Guin 2019-05-20 176 ★★★★★
20 Six Wakes Mur Lafferty 2019-05-20 364 ★★★★★
21 The Dead Zone Stephen King 2019-05-20 402 ★★★★✩
22 Dune (Dune Chronicles, #1) Frank Herbert 2019-04-24 687 ★★★★✩
23 The Incomplete Book of Running Peter Sagal 2019-04-24 197 ★★★★★
24 Lost Gods Brom 2019-04-24 496 ★★★★★
25 All Clear (All Clear, #2) Connie Willis 2019-04-24 656 ★★★✩✩
26 Blackout (All Clear, #1) Connie Willis 2019-03-14 610 ★★✩✩✩
27 A Man Called Ove Fredrik Backman 2019-03-14 337 ★★★✩✩
28 A Canticle for Leibowitz (St. Leibowitz, #1) Walter M. Miller Jr. 2019-03-12 334 ★★★★★
29 The Age of Agile: How Smart Companies Are Transforming the Way Work Gets Done Stephen Denning 2019-03-08 336 ★★★★★
30 The Curious Incident of the Dog in the Night-Time Mark Haddon 2019-03-08 226 ★★★★✩
31 Elevation Stephen King 2019-03-08 146 ★★★★★
32 Less Andrew Sean Greer 2019-03-08 273 ★★★★✩
33 Where'd You Go, Bernadette Maria Semple 2019-02-14 330 ★★★★★
34 Cryptonomicon Neal Stephenson 2019-02-14 1139 ★★★✩✩
35 The Cuckoo's Calling (Cormoran Strike, #1) Robert Galbraith 2019-02-11 455 ★★★★✩
36 Full Dark, No Stars Stephen King 2019-01-27 368 ★★★★★
37 Mr. Penumbra's 24-Hour Bookstore (Mr. Penumbra's 24-Hour Bookstore, #1) Robin Sloan 2019-01-23 288 ★★★★✩
38 Finding Ultra, Revised and Updated Edition: Rejecting Middle Age, Becoming One of the World's Fittest Men, and Discovering Myself Rich Roll 2019-01-23 400 ★★✩✩✩
39 Origin (Robert Langdon, #5) Dan Brown 2019-01-23 461 ★★★★✩
40 Lincoln in the Bardo George Saunders 2019-01-23 343 ★★★★✩
41 The Rise and Fall of D.O.D.O. Neal Stephenson 2019-01-23 752 ★★★★★
42 The Endless Knot (The Song of Albion, #3) Stephen R. Lawhead 2019-01-23 439 ★★★✩✩
43 Pet Sematary Stephen King 2019-01-23 580 ★★★★★

Add the HTML to my clipboard to copy to the blog


In [20]:
import clipboard

In [21]:
clipboard.copy(style_df.render())

In [ ]: