Skip to content
Advertisement

Pandas adding rows to dataframe

I’m trying to add more rows or records to my data frame, let’s say it looks like this:

JavaScript

and I have a CSV file stored in another data frame without headers

JavaScript

now I want a new data frame that looks like this

JavaScript

I have tried using append and concat but I didn’t get the result that I wanted

Advertisement

Answer

Assuming df1/df2, you can use set_axis to copy the axis of the first DataFrame, then concat:

JavaScript

output:

JavaScript

NB. ignore_index=True is optional, this is just to avoid having duplicated indices. Without it:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement