-1

My list has many elements. I want to save them to a newly created dataframe. I want to append each element of this list as a column element to the dataframe.

My code:

oplist = [[2,3,4,10,12,3,4],-0.4,1.23456E-6] # list saves all output values
opdf = pd.Dataframe() #creating an empty dataframe
opdf.append(oplist)

Present output:

TypeError: object of type 'numpy.float64' has no len()

Expected output:

opdf = 
          0                1        2      # unnamed columns
0    [2,3,4,10,12,3,4]   -0.4   1.23456E-6  # first row
AMC
  • 2,466
  • 7
  • 11
  • 31
Mainland
  • 1,600
  • 1
  • 7
  • 16
  • 1
    Is this what you were looking for? `opdf = pd.DataFrame() #creating an empty dataframe` `opdf.append(pd.Series(oplist), ignore_index=True)` – XXavier Apr 27 '20 at 01:11
  • What is the issue, exactly? What do you understand from that error message? Repeatedly appending to a DataFrame is unidiomatic and will likely be sluggish, can you provide some more context for this? – AMC Apr 27 '20 at 02:19
  • Does this answer your question? [Add one row to pandas DataFrame](https://stackoverflow.com/questions/10715965/add-one-row-to-pandas-dataframe) – AMC Apr 27 '20 at 02:20

1 Answers1

2

I do not know what exactly you are looking for but this gives you the output you have there

opdf = pd.DataFrame() #creating an empty dataframe
opdf.append(pd.Series(oplist), ignore_index=True)
XXavier
  • 921
  • 1
  • 6
  • 14