Pandas Highcharts 可視化示例
Highcharts是一個很棒的可視化工具,我們找到了GitHub上一個Python對應的項目pandas-highcharts,復盤一下用Pandas-highcharts做可視化。
你可登錄科賽 kesci ,打開K - Lab在線數據分析協作工具,在線開展可視化實踐,復現本篇代碼
K - Lab提供Python2、Python3、R三種語言環境,支持1000+工具包在線調用,點擊鏈接,Fork教程,即刻開始數據分析。
# 預先安裝一下這個package# !pip install pandas_highcharts
from pandas_highcharts.display import display_chartsfrom pandas_highcharts.core import serializeimport pandas as pd
導入數據
數據集源自 Quandl,具體的下載鏈接請戳這裡
# Data retrieved from http://www.quandl.com/api/v1/datasets/ODA/DEU_PCPIPCH.csv?coldf = pd.read_csv(../input/pandas_highchar7842/pandas_highcharts_demo.csv,index_col=0, parse_dates=True)df = df.sort_index()df.head()
基礎示例
- basic chart
display_charts(df, title="德國通貨膨脹率")
- stock-style chart
display_charts(df, chart_type="stock", title="德國通貨膨脹率")
- bar chart
display_charts(df, kind="bar", title="德國通貨膨脹率")
- horizontal bar
display_charts(df, kind="barh", title="德國通貨膨脹率")
- 設置圖片尺寸
display_charts(df, title="德國通貨膨脹率", legend=None, kind="bar", figsize = (400, 200))
display_charts(df, title="德國通貨膨脹率", kind="bar", render_to="chart5", zoom="xy")
- pie chart
# Data retrieved from https://www.quandl.com/api/v1/datasets/CVR/ANGEL_SECTORS.csvfrom pandas.compat import StringIOdata = """Year,Software,Healthcare,Hardware,Biotech,Telecom,Manufacturing,Financial Products and Services,IT Services,Industrial/Energy,Retail,Media
2013-12-31,23.0,14.0,,11.0,,,7.0,,,7.0,16.0
2012-12-31,23.0,14.0,,11.0,,,,,7.0,12.0,7.0
2011-12-31,23.0,19.0,,13.0,,,,7.0,13.0,,5.0
2010-12-31,16.0,30.0,,15.0,,,,5.0,8.0,5.0,
2009-12-31,19.0,17.0,,8.0,,,5.0,,17.0,9.0,
2008-12-31,13.0,16.0,,11.0,,,,,8.0,12.0,7.0
2007-12-31,27.0,19.0,,12.0,,,,,8.0,6.0,5.0
2006-12-31,18.0,21.0,,18.0,,,6.0,,6.0,8.0,
2005-12-31,18.0,20.0,8.0,12.0,,,,6.0,6.0,,6.0
2004-12-31,22.0,16.0,10.0,10.0,6.0,,8.0,8.0,,7.0,
2003-12-31,26.0,13.0,12.0,11.0,5.0,12.0,,,,,
2002-12-31,40.0,14.0,5.0,5.0,5.0,,,,,,
"""df3 = pd.read_csv(StringIO(data), index_col=0, parse_dates=True)df3 = df3.fillna(0) / 100df4 = pd.DataFrame(df3.mean(), columns=[ratio])df4[total] = 1
display_charts(df4, kind=pie, y=[ratio], title=Angel Deals By Sector, tooltip={pointFormat: {series.name}: <b>{point.percentage:.1f}%</b>})
推薦閱讀:
※預測:國內可視化數據分析工具2018功能趨勢
※R語言互動式可視化包CanvasXpress
※數據可視化的開源方案: Superset vs Redash vs Metabase (二)
※關於數據可視化的一些思考
TAG:數據可視化 |