0

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",
TenkMan
  • 27
  • 4

2 Answers2

1

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

Also you could check this question

fukurowl
  • 67
  • 7
  • Thank you for the quick response. I read the first one and tried to implement it but I got this. I just keep getting everything in one long string as it is printed.Thank you. 0 balanceSheetHistory [{'2019-12-31': {'capitalSurplus': 22165000000... – TenkMan Dec 15 '20 at 03:26
1

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]
Jonathan Leon
  • 5,440
  • 2
  • 6
  • 14