How to transpose a dataset in a csv file?

后端 未结 7 996
太阳男子
太阳男子 2020-11-30 01:32

For example, i would like to transform:

Name,Time,Score
Dan,68,20
Suse,42,40
Tracy,50,38

Into:

Name,Dan,Suse,Tracy
Time,68,         


        
相关标签:
7条回答
  • 2020-11-30 02:10
    from itertools import izip
    from csv import reader, writer
    
    with open('source.csv') as f, open('destination.csv', 'w') as fw:
        writer(fw, delimiter=',').writerows(izip(*reader(f, delimiter=',')))
    
    0 讨论(0)
提交回复
热议问题