<h2>使用<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.io.json.json_normalize.html#pandas-io-json-json-normalize" rel="nofollow noreferrer">^{<cd1>}</a>:</h2>
<ul>
<li>这将为您提供<code>json_obj</code>中的所有内容</li>
<li>为顶键创建数据帧,但<code>records</code>不会展开</li>
<li>为<code>records</code>创建包含顶层<code>uri</code>的数据帧</li>
<li>在两个数据帧上使用<code>pd.merge</code></li>
</ul>
<pre class="lang-py prettyprint-override"><code>import pandas as pd
from pandas.io.json import json_normalize
df_top = json_normalize(json_obj)
# drop the unexpanded records column
df_top.drop(columns='records', inplace=True)
df_rec = json_normalize(data, 'records', ['uri'], meta_prefix='top')
df_merged = pd.merge(df_rec, df_top, left_on='topuri', right_on='uri')
# drop and rename columns
df_m.drop(columns='topuri', inplace=True)
df_m.rename(columns={'uri_x': 'records.uri', 'uri_y': 'top.uri'}, inplace=True)
# df_merged view
records.uri id sessionId startTime duration type direction action result to.phoneNumber from.name from.phoneNumber from.extensionId recording.uri recording.id recording.type recording.contentUri extension.uri extension.id top.uri paging.page paging.perPage paging.pageStart paging.pageEnd navigation.nextPage.uri navigation.firstPage.uri navigation.lastPage.uri
https://platform.ringcentral.com/restapi/v1.0/account/123456/call-log/123456?view=Simple 123456 123456 2019-10-09T20:47:26.577Z 45 Voice Outbound VoIP Call Call connected 123456 Jane Doe 123456 123456 https://platform.ringcentral.com/restapi/v1.0/account/123456/recording/123456 123456 Automatic https://media.ringcentral.com/restapi/v1.0/account/123456/recording/581514130067/content https://platform.ringcentral.com/restapi/v1.0/account/123456/extension/1409182064 123456.0 https://platform.ringcentral.com/restapi/v1.0/account/123456/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2019-10-09T16:00:00.000Z&page=1&perPage=2 1 2 0 1 https://platform.ringcentral.com/restapi/v1.0/account/123456/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2019-10-09T16:00:00.000Z&page=2&perPage=2 https://platform.ringcentral.com/restapi/v1.0/account/123456/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2019-10-09T16:00:00.000Z&page=1&perPage=2 https://platform.ringcentral.com/restapi/v1.0/account/123456/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2019-10-09T16:00:00.000Z&page=1&perPage=2
https://platform.ringcentral.com/restapi/v1.0/account/123456/call-log/123456?view=Simple 123456 123456 2019-10-09T20:37:49.540Z 7 Voice Inbound Phone Call Missed 123456 Bob Smith 123456 NaN NaN NaN NaN NaN NaN NaN https://platform.ringcentral.com/restapi/v1.0/account/123456/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2019-10-09T16:00:00.000Z&page=1&perPage=2 1 2 0 1 https://platform.ringcentral.com/restapi/v1.0/account/123456/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2019-10-09T16:00:00.000Z&page=2&perPage=2 https://platform.ringcentral.com/restapi/v1.0/account/123456/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2019-10-09T16:00:00.000Z&page=1&perPage=2 https://platform.ringcentral.com/restapi/v1.0/account/123456/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2019-10-09T16:00:00.000Z&page=1&perPage=2
</code></pre>
<ul>
<li><code>uri_x</code>是记录中的uri,并重命名为<code>records.uri</code></li>
<li><code>uri_y</code>&;<code>topuri</code>都是顶层<code>uri</code>,它们在合并时被保留
<ul>
<li>删除<code>topuri</code>并将<code>uri_y</code>重命名为<code>top.uri</code></li>
</ul></li>
<li>根据需要删除或重命名任何其他列,或仅使用所需列创建单独的数据框</li>
<li>要保存,请使用<code>df.to_csv</code>或其他一些<a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html" rel="nofollow noreferrer">output options</a>。你知道吗</li>
</ul>
<h2>注:</h2>
<ul>
<li>如果您只需要<code>records</code>(<code>from</code>在记录中),那么您只需要以下数据帧<code>df_rec = json_normalize(data, 'records')</code>,而不需要合并。你知道吗</li>
</ul>