Python Forum
Inserting a python list into a dataframe column wise
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inserting a python list into a dataframe column wise
#1
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"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding PD DataFrame column bsben 2 241 Mar-08-2024, 10:46 PM
Last Post: deanhystad
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 686 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  python script for inserting rows into hbase table lravikumarvsp 7 6,999 Mar-24-2023, 04:44 AM
Last Post: parth_botadara
  Difference one column in a dataframe Scott 0 619 Feb-10-2023, 08:41 AM
Last Post: Scott
  splitting a Dataframe Column in two parts nafshar 2 910 Jan-30-2023, 01:19 PM
Last Post: nafshar
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 797 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  renaming the 0 column in a dataframe Led_Zeppelin 5 1,458 Aug-16-2022, 04:07 PM
Last Post: deanhystad
  function returns dataframe as list harum 2 1,336 Aug-13-2022, 08:27 PM
Last Post: rob101
  Copy a column from one dataframe to another dataframe Led_Zeppelin 17 10,981 Jul-08-2022, 08:40 PM
Last Post: deanhystad
  Reshaping a single column in to multiple column using Python sahar 7 1,967 Jun-20-2022, 12:35 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020