Python Forum

Full Version: Inserting a python list into a dataframe column wise
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have the following python list,

test_list = 
[ ['CVM', 20010618, 332.5],
['CVM', 20010619, 332.5],
['CVM', 20010620, 330.0],
['CVM', 20010621, 342.5],
['CVM', 20010622, 337.5],
['AEF', 19970102, 18.7489],
['AEF', 19970103, 18.9735],
['AEF', 19970106, 19.5348],
['AEF', 19970107, 19.6471] ]
I want to concat it into a dataframe with axis=1, so it would be like that in the dataframe

<TICKER><DTYYYYMMDD><CLOSE><TICKER><DTYYYYMMDD><CLOSE>
'CVM' 20010619 332.5 'AEF' 19970102 18.7489
'CVM' 20010620 330.0 'AEF' 19970103 18.9735
'CVM' 20010621 342.5 'AEF' 19970106 19.5348
'CVM' 20010622 337.5 'AEF' 19970107 19.6471

I use the following code:

frame = pd.concat(test_list, axis=1, ignore_index=True)
but I get the following error "TypeError: cannot concatenate object of type "<class 'list'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid"