["python","pandas"]
How do I combine two dataframes?

I have a initial dataframe D. I extract two data frames from it like this: A = D[D.label == k] B = D[D.label != k] I want to combine A and B into one DataFrame. The order of the data is not important. However, when we sample A and B from D, they retain their indexes from D.
Updated in 2025 df_merged = pandas.concat([df1, df2], ignore_index=True, sort=False) ** OLD ANSWER** DEPRECATED: DataFrame.append and Series.append were deprecated in v1.4.0. Use append: df_merged = df1.append(df2, ignore_index=True) And to keep their indexes, set ignore_index=False.