Home > front end >  How to use concat instead of append, without having any Future Warning
How to use concat instead of append, without having any Future Warning

Time:09-16

I am using append

DF= pd.DataFrame(columns=['Col1', 'Col2', 'Col3'])
DF = DF.append({'Col1': "A",  'Col2'  : 'B'  ,'Col3':  'C'},ignore_index=True)

Which was working fine, Now I try to use concat instead :

DF= pd.DataFrame(columns=['Col1', 'Col2', 'Col3'])
DF = pd.concat([DF],pd.DataFrame({'Col1': ['A'],'Col2':['B'],'Col3':['C']}))

But this does throw the following error:

TypeError: unhashable type: 'DataFrame'

What am I doing wrong ?

CodePudding user response:

pd.concat takes a list of dataframes to concatenate as the first argument. You should put both the dataframes in the list:

DF= pd.DataFrame(columns=['Col1', 'Col2', 'Col3'])
DF = pd.concat([DF, pd.DataFrame({'Col1': ['A'],'Col2':['B'],'Col3':['C']})])
  • Related