Home > Blockchain >  ValueError: 1 columns passed, passed data had 3 columns
ValueError: 1 columns passed, passed data had 3 columns

Time:10-19

I had ['PREC_MM', 'DVENTO', 'PRESS_HPA'] and [0, 109, 914.1]

I want to combine this

df = pd.DataFrame([value_list], columns=[element_list])

CodePudding user response:

It looks like you are making a list of your list.

I assume that [0,109,914.1] is value_list (or element_list, doesn't matter for what I say).

If you have value_list = [0,109,914.1], then value_list is a list. When you call pd.DataFrame([value_list]...), you wrap value_list in another list, and you are effectively sending in a list that has a single item, and that item is a list that has three elements.

try just: df = pd.DataFrame(value_list,columns=element_list) without the brackets around the params.

CodePudding user response:

Try this:

import pandas as pd

element_list = ['PREC_MM', 'DVENTO', 'PRESS_HPA']
value_list = [0, 109, 914.1]
df = pd.DataFrame([value_list], columns=element_list)
   PREC_MM     DVENTO   PRESS_HPA
0        0        109       914.1
  • Related