Created
November 1, 2014 02:06
-
-
Save t0mst0ne/3451406fb807ca6a58da to your computer and use it in GitHub Desktop.
parse from portal.g0v.ronny.tw to pandas (財政部關務署進出口資料)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import json | |
import requests | |
url = 'http://portal-api.g0v.ronny.tw/api/searchgoodidcountry/in/1201/%E5%B7%B4%E8%A5%BF' | |
url2 = 'http://portal-api.g0v.ronny.tw/api/searchgoodidcountry/in/1201/%E7%BE%8E%E5%9C%8B' | |
src = json.loads(requests.get(url).text) | |
src2 = json.loads(requests.get(url2).text) | |
df = pd.DataFrame.from_dict(src['data']) | |
df['country'] = src['country'] | |
df2 = pd.DataFrame.from_dict(src2['data']) | |
df2['country'] = src2['country'] | |
df = df.append(df2) | |
df_pilot = pd.tools.pivot.pivot_table(df, values='Weight', index=['Time'], columns=['country'],aggfunc=np.sum, margins = False) | |
Fig = df_pilot.plot(kind='bar',stacked=True) | |
Fig = matplotlib.pyplot.gcf() | |
Fig.set_size_inches(40,20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment