I have a dataframe d1 like this:
From this, i want to extract another dataframe d2 like:
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.