I have a pandas data frame known as "df":
x y
0 1 2
1 2 4
2 3 8
I split it into two frames, and then try to combine them together:
df_1 = df[df['x']==1]
df_2 = df[df['x']!=1]
My goal is to return it in the same order, but when I agree, I get the following:
frames = [df_1, df_2]
solution = pd.concat(frames)
solution.sort_values(by='x', inplace=False)
x y
1 2 4
2 3 8
0 1 2
The problem is that I need the "x" values to return to the new data framework in the same order that I extracted. Is there a solution?
source
share