PYTHON SHELF EXTENSION

Python Shelve Extension

Extend standard library shelve module. Create a new shelf db that contains a dataframe and a figure.

In [1]:
import pandas as pd
import myshelf
import matplotlib.pyplot as plt
In [2]:
# Dataframe
df = pd.read_csv("https://tessarinseve.pythonanywhere.com/staticweb/dataset_1000.csv",index_col=0)
In [3]:
plt.scatter(df["Col1"].values, df["Col2"].values, alpha=0.2,
            c=df["Col5"].values, cmap='viridis')
Out[3]:
<matplotlib.collections.PathCollection at 0x252f0e888b0>
In [4]:
from io import BytesIO
In [5]:
png_string = BytesIO()
In [6]:
plt.savefig(png_string,format="png",backend="Agg")
<Figure size 432x288 with 0 Axes>
In [7]:
with myshelf.open_default("db_notebook") as nbshelf:
    nbshelf["dataframe"] = df
    nbshelf["png"] = png_string
In [8]:
myshelf.get_dir()
Out[8]:
'C:\\Users\\Seve\\My Documents\\My Shelf'

Inspect DB

In [9]:
db = myshelf.open_default("db_notebook") 
In [10]:
db.inspect()
KEY        TYPE                                   VALUE
========================================================
dataframe  <class 'pandas.core.frame.DataFrame'>              Col1      Col2      Col3      Col4  Col5
png        <class '_io.BytesIO'>                  <_io.BytesIO object at 0x00000252F2F78B80>

Video

In [11]:
from IPython.display import YouTubeVideo
In [12]:
YouTubeVideo("5GCc8xc7Ndg")
Out[12]:
In [ ]: