Converting List to pandas DataFrame -


i need build dataframe specific structure. yield curve values data, single date index, , days maturity column names.

in[1]: yield_data  # list of size 38, yield values out[1]:  [0.096651956137087325,  0.0927199778042056,  0.090000225505577847,  0.088300016028163508,...   in[2]: maturity_data  # list of size 38, days until maturity out[2]: [6,  29,  49,  70,...  in[3]: today out[3]:  timestamp('2017-07-24 00:00:00') 

then try create dataframe

pd.dataframe(data=yield_data, index=[today], columns=maturity_data) 

but returns error

valueerror: shape of passed values (1, 38), indices imply (38, 1) 

i tried using transpose of these lists, not allow transpose them.

how can create dataframe?

iiuc, think want dataframe single row, need reshape data input list list of list.

yield_data = [0.09,0.092, 0.091] maturity_data = [6,10,15] today = pd.to_datetime('2017-07-25')  pd.dataframe(data=[yield_data],index=[today],columns=maturity_data) 

output:

              6      10     15 2017-07-25  0.09  0.092  0.091 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -