-5

I want this output which is in dict to be converted into a pandas DataFrame with few columns of interest. Note my output is actually more but I have posted only part of the output but I hope you can understand what I actually want

My dataframe should have columns `['Date','Change in OI','Open interest']. preferably Date should be index.

strikes=[690,700,710]
data={}
for s in strikes:
    data[s]=get_history(symbol="CIPLA",
                        start=date(2020,7,1),
                        end=date(2201,7,17),
                        option_type="CE",
                        strike_price=s,
                        expiry_date=date(2020,7,30))

OUTPUT

{690:            Symbol      Expiry Option Type  Strike Price   Open   High    Low  \
 Date                                                                           
 2020-07-01  CIPLA  2020-07-30          CE         690.0  11.50  11.50   7.70   
 2020-07-02  CIPLA  2020-07-30          CE         690.0   8.90  20.90   8.50   
 2020-07-03  CIPLA  2020-07-30          CE         690.0  17.75  17.75  12.00   
 2020-07-06  CIPLA  2020-07-30          CE         690.0  11.30  11.30   9.60   
 2020-07-07  CIPLA  2020-07-30          CE         690.0  10.70  12.25  10.60   
 2020-07-08  CIPLA  2020-07-30          CE         690.0  12.95  14.10  11.45   
 2020-07-09  CIPLA  2020-07-30          CE         690.0  14.00  14.00  11.60   
 2020-07-10  CIPLA  2020-07-30          CE         690.0  12.50  13.00  10.95   
 2020-07-13  CIPLA  2020-07-30          CE         690.0  11.10  11.65   9.65   
 2020-07-14  CIPLA  2020-07-30          CE         690.0  10.65  10.70   8.40   
 2020-07-15  CIPLA  2020-07-30          CE         690.0   7.55  10.00   7.55   
 2020-07-16  CIPLA  2020-07-30          CE         690.0  11.20  18.65   7.25   
 2020-07-17  CIPLA  2020-07-30          CE         690.0  18.85  25.75  14.80   
 
             Close   Last  Settle Price Number of Contracts      Turnover  \
 Date                                                                       
 2020-07-01   8.85   8.85          8.85                  66  5.995900e+07   
 2020-07-02  16.85  20.50         16.85                  68  6.235500e+07   
 2020-07-03  13.00  13.25         13.00                 117  1.069840e+08   
 2020-07-06  10.65  10.75         10.65                  76  6.918800e+07   
 2020-07-07  11.00  11.00         11.00                  64  5.836300e+07   
 2020-07-08  11.95  11.95         11.95                  84  7.674300e+07   
 2020-07-09  12.00  12.00         12.00                  25  2.284000e+07   
 2020-07-10  11.10  11.10         11.10                  50  4.564100e+07   
 2020-07-13  10.05  10.05         10.05                  36  3.278000e+07   
 2020-07-14   8.50   8.40          8.50                  39  3.546700e+07   
 2020-07-15   8.45   8.40          8.45                  31  2.816200e+07   
 2020-07-16  17.20  16.80         17.20                 803  7.350000e+08   
 2020-07-17  20.05  19.30         20.05                1708  1.577693e+09   
 
             Premium Turnover Open Interest Change in OI  Underlying  
 Date                                                                 
 2020-07-01          757000.0        119600         5200         NaN  
 2020-07-02         1359000.0        113100        -6500      646.20  
 2020-07-03         2035000.0        131300        18200      638.80  
 2020-07-06         1016000.0        123500        -7800         NaN  
 2020-07-07          955000.0        128700         5200      636.55  
 2020-07-08         1395000.0        130000         1300         NaN  
 2020-07-09          415000.0        130000            0         NaN  
 2020-07-10          791000.0        130000            0         NaN  
 2020-07-13          488000.0        123500        -6500         NaN  
 2020-07-14          484000.0        115700        -7800         NaN  
 2020-07-15          355000.0        124800         9100         NaN  
 2020-07-16        14709000.0        302900       178100         NaN  
 2020-07-17        45617000.0        243100       -59800      689.10  }

the same goes on for the values in strikes=[700,710] in output

Already tried using pd.DataFrame.from_dict(data) no use

Guru Dath
  • 11
  • 2
  • Show code or output as properly formatted text in the question, not as image or external link. – Michael Butscher Jul 19 '20 at 06:52
  • Welcome to SO. Please read https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples. Then rephrase your question with the relevant data **as text**, and please include the expected output as well. – Roy2012 Jul 19 '20 at 06:55
  • "output of my code" where is your code? – deadshot Jul 19 '20 at 06:56

2 Answers2

1

You can try the following approaches

1.

import pandas as pd
df =  pd.DatFrame(<<your dictionary>>)   # you can pass the dictionary 
  1. Alternatively you can also use the following
import pandas as pd

cols = [<<list of column names>>]   # to specify different column names 

df = pd.DataFrame.from_dict(<<dictionary name>>,columns=cols)
deadshot
  • 8,881
  • 4
  • 20
  • 39
Praks
  • 67
  • 1
  • 1
  • 4
0

use your dictionary in this way to convert it into a dataframe

import pandas as pd
df = pd.DataFrame({"your dictionary here"})
deadshot
  • 8,881
  • 4
  • 20
  • 39