Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. index country value1 value2 value3
  2. 0 USA 6 5 4
  3. 1 USA 4 7 3
  4. 2 USA 3 2 1
  5. 3 CAN 4 5 7
  6. 4 CAN 10 8 6
  7.  
  8. index USA CAN
  9. 0 6 4
  10. 1 4 10
  11. 2 3 NaN
  12.  
  13. column = ['USA', 'CAN']
  14. df_value1 = pd.DataFrame(columns=column)
  15. temp = df['value1'].where(df['country']=='USA').dropna()
  16. df_value1['USA'] = temp
  17. temp = df['value1'].where(df['country']=='CAN').dropna()
  18. pd.concat([df_value1, temp], axis=1, ignore_index=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement