我想打开一个csv文件,转置(或交换)行和列,然后仅将一列写入新文件。输出文件应该是73行长,但是每次我得到以下输出时:
Province/State NaN
Country/Region Lebanon
Lat 33.8547
Long 35.8623
1/22/20 0
...
3/26/20 368
3/27/20 391
3/28/20 412
3/29/20 438
3/30/20 446
Name: 147, Length: 73, dtype: object
这是python代码:
import pandas as pd
inp_file = pd.read_csv('input_file.csv')
out_file = inp_file.T
#I have also tried out_file=inp_file.transpose()
f = open("output_file.csv", "w")
f.write(str(out_file[147]))
f.close()
是否有办法将完整的原始行作为输出文件中的一列?
谢谢