简体   繁体   中英

Combine two dataframes according to the values in one of the columns

dataframe1
data_a           data_b      data_c    data_d    data_e
61               0.30792          Rest 2.34857    True
183              0.93408          Rest 2.34550    True
305              1.56019          Rest 2.34215    True
427              2.18636          Rest 2.33955    True
549              2.81252          Rest 2.33660    True

dataframe2
data_a           data_b      data_c    data_d    data_e
122              0.62616     Discharge 2.32013   False
244              1.25233     Discharge 2.31390   False
366              1.87844     Discharge 2.31087   False
488              2.50460     Discharge 2.30819   False
610              3.13077     Discharge 2.30567   False

I would like the out put to be as follows:

dataframe3
data_a           data_b      data_c    data_d    data_e
61               0.30792          Rest 2.34857    True
122              0.62616     Discharge 2.32013   False
183              0.93408          Rest 2.34550    True
244              1.25233     Discharge 2.31390   False
305              1.56019          Rest 2.34215    True
366              1.87844     Discharge 2.31087   False
427              2.18636          Rest 2.33955    True
488              2.50460     Discharge 2.30819   False
549              2.81252          Rest 2.33660    True
610              3.13077     Discharge 2.30567   False

As you can see, the new dataframe should be sorted by according to the sequential order of the values in the data_a column.

检查concat然后sort_values

df3 = pd.concat([df1, df2]).sort_values('data_a')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM