Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error when adding a new row to my existing dataframe in pandas

I have the below data frame.

df3=pd.DataFrame(columns=["Devices","months"])

I am getting row value from a loop row, print(data)

    Devices     months
1  Powerbank  Feb month

When I am adding this data row to my df3 I am getting an error.

  df3.loc[len(df3)]=data

ValueError: cannot set a row with mismatched columns

like image 787
pyco Avatar asked Jul 14 '17 14:07

pyco


1 Answers

use

df3 = pd.concat([df3, data], axis=0)

or as suggested by @Wen use

df3 = df3.append(data)
like image 67
muon Avatar answered Sep 20 '22 19:09

muon