列中的列

时间:2016-06-15 09:10:52

标签: python json pandas dataframe

我正在尝试从网络API中提取数据框,但似乎无法解决如何打破列的问题。对于Home和Away,他们内部都有故障,所以应该阅读Home Wins,Home Draws等。

url = "http://api.football-data.org/v1/soccerseasons/398/leagueTable/?matchday=38"
response = requests.get(url)
response_json = response.content
result = json.loads(response_json)
football = pd.DataFrame(result['standing'], columns=['position','teamName','playedGames','wins','draws','losses','goals', 
                                                 'goalsAgainst','home','away','goalDifference','points'])
football

football.home

这显示了问题:

0     {u'wins': 12, u'losses': 1, u'draws': 6, u'goa...

1 个答案:

答案 0 :(得分:0)

我认为您可以使用json_normalize

Intent
import pandas as pd
import json
import requests
from pandas.io.json import json_normalize  

url = "http://api.football-data.org/v1/soccerseasons/398/leagueTable/?matchday=38"

result = json.loads(requests.get(url).text)
#print (result)

df = json_normalize(result["standing"])