简体   繁体   中英

How to use concat instead of append, without having any Future Warning

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?

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']})])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM