擅长:python、mysql、java
<p>Pandas库将在这里提供帮助,不过提取嵌套json更多的是python技能。您可以按照以下步骤简单地提取所需的列:</p>
<pre><code>import pandas as pd
url = 'https://restcountries.eu/rest/v2/all';
#Load json to a dataframe
df = pd.read_json(url);
# Create DF with Country, capital and code fields. You can use df.head() to see how your data looks in table format and columns name.
df_new = df[['name', 'capital', 'alpha2Code', 'alpha3Code']].copy()
#Use pandas ExcelWriter to write the desired DataFrame to xlsx file.
with pd.ExcelWriter('country_names.xlsx') as writer:
df_new.to_excel(writer, sheet_name="Country List")
</code></pre>
<p><a href="https://i.stack.imgur.com/T1BQX.png" rel="nofollow noreferrer">Sample Data from the generated Excel File</a></p>
<p>有关ExcelWriter模块的完整信息,请访问<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_excel.html" rel="nofollow noreferrer">https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_excel.html</a></p>
<p>您需要改变列名并清理数据(尤其是嵌套对象),而这些应该只是一个搜索</p>