Python + Pandas + Dataframe : Couldn't Append One Dataframe To Another
I have two big CSV files. I have converted them to Pandas dataframes. Both of them have columns of same names and in same order : event_name, category, category_id, description. I
Solution 1:
Whats wrong with a simple:
pd.concat([df1, df2], ignore_index=True)).to_csv('File.csv', index=False)
this will work if they have the same columns.
A more verbose way to extract specific columns would be:
(pd.concat([df1[['event_name','category', 'category_id', 'description']],
df2[['event_name','category', 'category_id', 'description']]],
ignore_index=True))
.to_csv('File.csv', index=False))
Separate Notes:
- you are initializing a DF with just columns and then outputting that to a CSV.
- Why are you using
.squeeze
to convert it to 1-D dataset?
Post a Comment for "Python + Pandas + Dataframe : Couldn't Append One Dataframe To Another"