Home > Software design >  How to reformat horizontal csv to a more vertical format
How to reformat horizontal csv to a more vertical format

Time:12-12

enter image description here

The above CSV is just a small snippet of the data, there are lots of data entries.

A simple transpose will not work

I need to get into the following format:

enter image description here

I have tried some methods with pandas and transpose but cannot figure it out. The CSV could be potentially thousands of lines long

CodePudding user response:

You read the data by using pandas, and transpose the dataframe

df = pd.read_csv('name_file.csv')

df_trans = df.T

CodePudding user response:

You can use:

#if entry is index, remove "set_index('Entry')" field.
final=pd.concat([df[:4].set_index('Entry').T,df[4:].set_index('Entry').T])
  • Related