Pandas Highcharts Example

Import


In [1]:
%load_ext autoreload
%autoreload 2

import pandas as pd
import datetime
import os
import numpy as np
from pandas.compat import StringIO
from pandas.io.common import urlopen
from IPython.display import display, display_pretty, Javascript, HTML
from pandas_highcharts.core import serialize
from pandas_highcharts.display import display_charts
import matplotlib.pyplot as plt

# Data retrieved from http://www.quandl.com/api/v1/datasets/ODA/DEU_PCPIPCH.csv?column=1
data = """Date,Value\n2019-12-31,1.7\n2018-12-31,1.7\n2017-12-31,1.7\n2016-12-31,1.5\n2015-12-31,1.247\n2014-12-31,0.896\n2013-12-31,1.601\n2012-12-31,2.13\n2011-12-31,2.498\n2010-12-31,1.158\n2009-12-31,0.226\n2008-12-31,2.738\n2007-12-31,2.285\n2006-12-31,1.784\n2005-12-31,1.92\n2004-12-31,1.799\n2003-12-31,1.022\n2002-12-31,1.346\n2001-12-31,1.904\n2000-12-31,1.418\n1999-12-31,0.626\n1998-12-31,0.593\n1997-12-31,1.542\n1996-12-31,1.19\n1995-12-31,1.733\n1994-12-31,2.717\n1993-12-31,4.476\n1992-12-31,5.046\n1991-12-31,3.474\n1990-12-31,2.687\n1989-12-31,2.778\n1988-12-31,1.274\n1987-12-31,0.242\n1986-12-31,-0.125\n1985-12-31,2.084\n1984-12-31,2.396\n1983-12-31,3.284\n1982-12-31,5.256\n1981-12-31,6.324\n1980-12-31,5.447\n"""
df = pd.read_csv(StringIO(data), index_col=0, parse_dates=True)
df = df.sort_index()


Basic examples


In [2]:
display_charts(df, title="Germany inflation rate")



In [3]:
display_charts(df, chart_type="stock", title="Germany inflation rate")



In [4]:
display_charts(df, kind="bar", title="Germany inflation rate")



In [5]:
display_charts(df, kind="barh", title="Germany inflation rate")



In [6]:
display_charts(df, title="Germany inflation rate", legend=None, kind="bar", figsize = (400, 200))



In [7]:
display_charts(df, title="Germany inflation rate", kind="bar", render_to="chart5", zoom="xy")



In [8]:
# Data retrieved from https://www.quandl.com/api/v1/datasets/CVR/ANGEL_SECTORS.csv
data = """Year,Software,Healthcare,Hardware,Biotech,Telecom,Manufacturing,Financial Products and Services,IT Services,Industrial/Energy,Retail,Media\n2013-12-31,23.0,14.0,,11.0,,,7.0,,,7.0,16.0\n2012-12-31,23.0,14.0,,11.0,,,,,7.0,12.0,7.0\n2011-12-31,23.0,19.0,,13.0,,,,7.0,13.0,,5.0\n2010-12-31,16.0,30.0,,15.0,,,,5.0,8.0,5.0,\n2009-12-31,19.0,17.0,,8.0,,,5.0,,17.0,9.0,\n2008-12-31,13.0,16.0,,11.0,,,,,8.0,12.0,7.0\n2007-12-31,27.0,19.0,,12.0,,,,,8.0,6.0,5.0\n2006-12-31,18.0,21.0,,18.0,,,6.0,,6.0,8.0,\n2005-12-31,18.0,20.0,8.0,12.0,,,,6.0,6.0,,6.0\n2004-12-31,22.0,16.0,10.0,10.0,6.0,,8.0,8.0,,7.0,\n2003-12-31,26.0,13.0,12.0,11.0,5.0,12.0,,,,,\n2002-12-31,40.0,14.0,5.0,5.0,5.0,,,,,,\n"""
df3 = pd.read_csv(StringIO(data), index_col=0, parse_dates=True)
df3 = df3.fillna(0) / 100
df4 = pd.DataFrame(df3.mean(), columns=['ratio'])
df4['total'] = 1

In [9]:
display_charts(df4, kind='pie', y=['ratio'], title='Angel Deals By Sector', tooltip={'pointFormat': '{series.name}: <b>{point.percentage:.1f}%</b>'})


Highcharts specific


In [10]:
df4 = pd.DataFrame(df3.sum(), columns=['sum'])
#df4.to_dict('series').items()[0][1].tolist()
display_charts(df4, polar=True, kind='bar', ylim=(0, 2.3), title='Angel Deals By Sector')