0

Good Day to all I have a problem transposing CSV file using python and pandas below are my codes.

import pandas as pd

df = pd.read_csv(r'TestData.csv')
df = df.groupby('Name')['Question'].apply(list)
df2 = df.T
df2.to_csv('file.csv')

I also attached the sample raw data and my needed output. Sample Screenshot

mozway
  • 81,317
  • 8
  • 19
  • 49
  • Hello I think I have the answer using below command import pandas as pd df = pd.read_csv(r'TestData.csv') df = df.groupby('Name')['Result'].apply(lambda df: df.reset_index(drop=True)).unstack() df.to_csv('file.csv') – Eon Flask Feb 07 '22 at 09:39

0 Answers0