擅长:python、mysql、java
<p><code>read_json</code>函数<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_json.html" rel="nofollow noreferrer">expects</a>字符串。您提供了一个JSON对象(使用<code>requests</code>库的<code>json</code>方法解析)。您需要做的是使用<code>json.dumps</code>方法将对象转换回字符串:</p>
<pre><code>import json
r = requests.get('http://api.football-data.org/v1/competitions/398/teams')
x = r.json()
df = pd.read_json(json.dumps(x))
</code></pre>
<p>或者更好的方法是,直接从请求对象获取缓冲区,不要将其转换为对象。</p>
<pre><code>r = requests.get('http://api.football-data.org/v1/competitions/398/teams')
df = pd.read_json(x.text)
</code></pre>