11  Playground

11.1 great tables

Load the sp500 from great_tables

import great_tables as gt
from great_tables.data import sp500
sp500.head()
date open high low close volume adj_close
0 2015-12-31 2060.5901 2062.5400 2043.62 2043.9399 2.655330e+09 2043.9399
1 2015-12-30 2077.3401 2077.3401 2061.97 2063.3601 2.367430e+09 2063.3601
2 2015-12-29 2060.5400 2081.5601 2060.54 2078.3601 2.542000e+09 2078.3601
3 2015-12-28 2057.7700 2057.7700 2044.20 2056.5000 2.492510e+09 2056.5000
4 2015-12-24 2063.5200 2067.3601 2058.73 2060.9900 1.411860e+09 2060.9900

11.2 itables

from itables.sample_dfs import get_countries
from itables import show

df = get_countries(html=False)
show(df, lengthMenu=[10, 25, 50, 100, 250])
region country capital longitude latitude
code
Loading ITables v2.2.2 from the internet... (need help?)

11.3 colorful table

import pandas as pd
import numpy as np

temps = pd.DataFrame({
  'year': [*range(1920, 1925)],
  'Jan': [40.6, 44.2, 37.5, 41.8, 39.3], 
  'Jun': [58.5, 58.7, 57.8, 52.7, 57.7]
}).set_index('year')

def make_pretty(styler):
  styler.background_gradient(axis=None,
    vmin=31, vmax=66, cmap="RdYlGn_r")
  return styler

temps.style.pipe(make_pretty)
  Jan Jun
year    
1920 40.600000 58.500000
1921 44.200000 58.700000
1922 37.500000 57.800000
1923 41.800000 52.700000
1924 39.300000 57.700000

11.4 Ddit Databases with Datasette

  • https://www.datasette.cloud/blog/2023/datasette-write-ui/