Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- index country value1 value2 value3
- 0 USA 6 5 4
- 1 USA 4 7 3
- 2 USA 3 2 1
- 3 CAN 4 5 7
- 4 CAN 10 8 6
- index USA CAN
- 0 6 4
- 1 4 10
- 2 3 NaN
- column = ['USA', 'CAN']
- df_value1 = pd.DataFrame(columns=column)
- temp = df['value1'].where(df['country']=='USA').dropna()
- df_value1['USA'] = temp
- temp = df['value1'].where(df['country']=='CAN').dropna()
- pd.concat([df_value1, temp], axis=1, ignore_index=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement