Ad

Append Small Data Frame To A Big One And Sort It

- 1 answer

I have a very large data frame with over 200k records and 7 columns.
I created another data frame in another function, and I made sure that the new data frame has the exact same 7 columns' names.
The information in the new data frame is extra details for some entries in the big data frame, so I need to sort it inside of the big one and not just append it at the end.
so after the records are attached, the whole data frame should be sorted by the values in column 'A', there will be many repeats for each value in that column and that is ok, but then I want these lines to be sorted by column 'B'.

Ad

Answer

concat & sort_values

df = pd.concat([big_df, small_df]).sort_values(['A', 'B'])
Ad
source: stackoverflow.com
Ad