0

I have this table as a csv file.

col1 col2 col3
15 y 55
z 12
99 y 26
25 y 14
z 88

And I expect this:

col1 y z
15 55 12
99 26 nan
25 14 88

I tried df.stack() but it didn't work

roben_zik
  • 1
  • 2
  • This should do it: `df.pivot(columns='col2', values='col3', index='col1').reset_index().rename_axis(None, axis=1)` –  Dec 24 '21 at 21:42
  • richardec, I tried what you suggested but it didn't work. I got this message error: ValueError: Index contains duplicate entries, cannot reshape – roben_zik Dec 26 '21 at 08:39

0 Answers0