0 votes
1 view
in Python by (15.9k points)

df = pd.DataFrame({'ProdcutID': {0: '2125',1: '1204',2: '4390'},







enter image description here

I have above weird dataframe and want to transform the columns into rows. I tried to use df.T but didn't get what I want. Probably use df.groupby('ProductID')...?

Expected results:

enter image description here

1 Answer

0 votes
by (25.1k points)

You can rename some columns and then use the wide_to_long method from pandas. Like this:

df1 = df.rename(columns={'Color':'Color0','From':'From0'})


Welcome to Intellipaat Community. Get your technical queries answered by top developers !