TenkMan
TenkMan

Reputation: 27

Python JSON to a dataframe

I am using a Yahoo finance Python library to grab accounting financial data to do some basic analysis. All of the financial statement data comes in JSON format. I want the data to be in a tabular format as I typically see in a Python dataframe. Hello there are several wrappers around the data and I'm not sure how to remove those so that I can get my data into a simple columns and rows dataframe. Here is what the Python looks like:

{
   "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",

Upvotes: 0

Views: 129

Answers (2)

Jonathan Leon
Jonathan Leon

Reputation: 5648

you don't have the full response so it's difficult to tell if this will be what you want

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'])

Output:

  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]

Upvotes: 1

fukurowl
fukurowl

Reputation: 67

You should use Pandas Here its a tutorial of how to do that with pandas

Also you could check this question

Upvotes: 1

Related Questions