简体   繁体   中英

How to move and append next row to previous row in the Pandas Dataframe

Can you please help for formatting the pandas dataframe, I want to move and append the next row in dataframe to the previous row. Below example -

Original DataFrame -

Required Dataframe

Thanks..!!

Ok, Was able to handle it as below -

Separate the dataframe based on the type and then merge as below -

a_df = df[df['type'] =='A']
b_df = df[df['type'] == 'B']
merged = a_df.merge(b_df, how='outer', on='data')

Thanks..!!

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