Search code examples
pandasappendconcatenation

tacking a row onto the bottom of a dataframe


I have two data frames:

DF1 = 14 rows x 49 columns (US States)

DF2 = 1 row x 49 columns (US states)

I'm trying to add DF2 on to the bottom of DF1 to create: 15 rows x 49 columns

I've tried append() and concat() and it keeps returning a dataframe which is: 15 rows x 98 columns all of which are NaN except for row 15 , columns 50:98. ??

result = census_data.append(total_guns_2007)

Solution

  • This is probably because the columns are different.

    Try this -

    total_guns_2007.columns = census_data.columns.values #this will make the column name same.
    result = census_data.append(total_guns_2007)