将Python JSON转换为数据帧
我正在使用Yahoo finance Python库获取会计财务数据,以进行一些基本分析。所有财务报表数据均采用JSON格式。我希望数据采用表格格式,就像我通常在Python数据帧中看到的那样。您好,数据周围有几个包装器,我不确定如何删除它们,以便将数据放入一个简单的列和行数据框中。下面是Python的外观:将Python JSON转换为数据帧,python,json,Python,Json,我正在使用Yahoo finance Python库获取会计财务数据,以进行一些基本分析。所有财务报表数据均采用JSON格式。我希望数据采用表格格式,就像我通常在Python数据帧中看到的那样。您好,数据周围有几个包装器,我不确定如何删除它们,以便将数据放入一个简单的列和行数据框中。下面是Python的外观: { "incomeStatementHistory":{ "F":[ { "2
{
"incomeStatementHistory":{
"F":[
{
"2019-12-31":{
"researchDevelopment":"None",
"effectOfAccountingCharges":"None",
"incomeBeforeTax":-640000000,
"minorityInterest":45000000,
"netIncome":47000000,
"sellingGeneralAdministrative":10218000000,
"grossProfit":12876000000,
"ebit":2658000000,
"operatingIncome":2658000000,
"otherOperatingExpenses":"None",
"interestExpense":-1049000000,
"extraordinaryItems":"None",
你应该用熊猫
您也可以选中此项您应该使用熊猫
此外,您还可以检查此项您没有完整的响应,因此很难判断这是否是您想要的
d = {
"incomeStatementHistory":{
"F":[
{
"2019-12-31":{
"researchDevelopment":"None",
"effectOfAccountingCharges":"None",
"incomeBeforeTax":-640000000,
"minorityInterest":45000000,
"netIncome":47000000,
"sellingGeneralAdministrative":10218000000,
"grossProfit":12876000000,
"ebit":2658000000,
"operatingIncome":2658000000,
"otherOperatingExpenses":"None",
"interestExpense":-1049000000,
"extraordinaryItems":"None",}}]}}
pd.json_normalize(d['incomeStatementHistory']['F'])
输出:
2019-12-31.researchDevelopment 2019-12-31.effectOfAccountingCharges 2019-12-31.incomeBeforeTax ... 2019-12-31.otherOperatingExpenses 2019-12-31.interestExpense 2019-12-31.extraordinaryItems
0 None None -640000000 ... None -1049000000 None
[1 rows x 12 columns]
你没有完整的回答,所以很难判断这是否是你想要的
d = {
"incomeStatementHistory":{
"F":[
{
"2019-12-31":{
"researchDevelopment":"None",
"effectOfAccountingCharges":"None",
"incomeBeforeTax":-640000000,
"minorityInterest":45000000,
"netIncome":47000000,
"sellingGeneralAdministrative":10218000000,
"grossProfit":12876000000,
"ebit":2658000000,
"operatingIncome":2658000000,
"otherOperatingExpenses":"None",
"interestExpense":-1049000000,
"extraordinaryItems":"None",}}]}}
pd.json_normalize(d['incomeStatementHistory']['F'])
输出:
2019-12-31.researchDevelopment 2019-12-31.effectOfAccountingCharges 2019-12-31.incomeBeforeTax ... 2019-12-31.otherOperatingExpenses 2019-12-31.interestExpense 2019-12-31.extraordinaryItems
0 None None -640000000 ... None -1049000000 None
[1 rows x 12 columns]
谢谢你的快速回复。我读了第一个,并试图实现它,但我得到了这个。我只是在打印的时候把所有的东西都放在一根长长的绳子里。谢谢。0 balanceSheetHistory[{'2019-12-31':{'capitalSurplus':2216500000…感谢您的快速响应。我阅读了第一个并尝试实现它,但我得到了这个。我只是在打印时一直以一个长字符串获取所有内容。谢谢。0 balanceSheetHistory[{'2019-12-31':{'capitalSurplus':2216500000。。。