Fred
Fred

Reputation: 583

python pandas: transform x-y-list to x-y-coordinate system

I have a dataframe df like

X Y value
1 1 foo
1 2 bar
2 1 lo
2 2 la

is there an elegant way to transform it into a x-y-map like

  1   2
1 foo bar
2 lo  la

Upvotes: 2

Views: 802

Answers (1)

Pygirl
Pygirl

Reputation: 13349

try:

df.set_index(['X', 'Y'])['value'].unstack()

Y   1   2
X       
1   foo bar
2   lo  la

Upvotes: 3

Related Questions