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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -