<ul>
<li>这假定从API返回的对象不是字符串(例如<code>'[{...}, {...}]'</code>)。
<ul>
<li>如果它是一个字符串,首先使用<code>data = json.loads(data)</code></li>
</ul>
</li>
<li>可以使用列表理解从{<cd6>}的{<cd5>}中提取{<cd3>}和相应的{<cd4>}</li>
<li>遍历<code>list</code>中的每个<code>dict</code>,并对<code>key</code>使用<code>dict.get</code>。如果键不存在,则返回<code>None</code></li>
</ul>
<pre class="lang-py prettyprint-override"><code>import pandas as pd
# where data is the list of dicts, unpack the desired keys and load into pandas
df = pd.DataFrame([{'date': i.get('date'), 'message': i.get('message')} for i in data])
# display(df)
date message
0 2020-09-03T14:51:03+00:00 Looking for product managers / engineers who have worked in search engine / query understanding space. Please PM me if you can connect me to someone for the same
1 2020-09-03T11:48:18+00:00 None
</code></pre>
<h2>或者</h2>
<ul>
<li>如果希望跳过数据,其中<code>'message'</code>是<code>None</code></li>
</ul>
<pre class="lang-py prettyprint-override"><code>df = pd.DataFrame([{'date': i['date'], 'message': i['message']} for i in data if i.get('message')])
date message
2020-09-03T14:51:03+00:00 Looking for product managers / engineers who have worked in search engine / query understanding space. Please PM me if you can connect me to someone for the same
</code></pre>