In [1]:
%matplotlib inline
In [2]:
import requests
import pandas as pd
import matplotlib
matplotlib.style.use('ggplot')
In [3]:
r = requests.get('http://m.au.ufc.com/fm/api/event/detail/778.json')
In [4]:
r.json().keys()
Out[4]:
In [5]:
r.json().get('Status')
Out[5]:
In [6]:
r.json().get('Attendance')
In [7]:
r.json().get('Name')
Out[7]:
In [8]:
r.json().get('statid')
Out[8]:
In [9]:
r.json().get('Location')
Out[9]:
In [10]:
r.json().get('Time')
Out[10]:
In [11]:
r.json().get('Date')
Out[11]:
In [12]:
r.json().get('GMT')
Out[12]:
In [13]:
r.json().get('Organization')
Out[13]:
In [14]:
len(r.json().get('FightCard'))
Out[14]:
In [15]:
r.json().get('FightCard')[1].keys()
Out[15]:
In [16]:
r.json()['FightCard'][1]['statid']
Out[16]:
In [17]:
pd.DataFrame.from_dict(r.json()['FightCard'][1]['Fighters'])
Out[17]:
In [52]:
df = pd.DataFrame(r.json()['FightCard'][1]['Stats'],
index = ['{FirstName} {LastName}'.format(**f['Name'])
for f in r.json()['FightCard'][1]['Fighters']],
dtype = 'float64')
df.drop(['statid'], axis=1, inplace=True)
df
Out[52]:
In [63]:
df.T.plot.barh(figsize=(10, 10))
Out[63]:
In [54]:
df['TotalStrikesMissed'] = df['TotalStrikesAttempted']- df['TotalStrikesLanded']
In [60]:
df[['TotalStrikesLanded', 'TotalStrikesMissed']].plot.bar(stacked=True)
Out[60]:
In [91]:
df[['TotalStrikesLanded', 'TotalStrikesMissed']].T.plot.pie(subplots=True, autopct='%.2f', figsize=(10, 5))
Out[91]:
In [ ]: