0

I have a dataframe d1 like this:

enter image description here

From this, i want to extract another dataframe d2 like:

enter image description here

Naively, i'm trying the below code:

d2 = pd.DataFrame(index=d1['X'].unique(), columns=d1['Y'].unique())
for i in d1['X'].unique():
    for j in d1['Y'].unique():
        d2.loc[i,j]=d1[(d1['X']==i) & (d1['Y']==j)]['Z']

But in gives: ValueError: Incompatible indexer with Series

I'm a beginner and any help would mean a lot! Thanks.

mozway
  • 194,879
  • 13
  • 39
  • 75
Arunachal
  • 1
  • 1

0 Answers0