我想打開一個csv文件,轉(zhuǎn)置(或交換)行和列,然后只將一列寫入新文件。輸出文件應該有73行長,但每次我得到這個輸出:Province/State NaNCountry/Region LebanonLat 33.8547Long 35.86231/22/20 0 ... 3/26/20 3683/27/20 3913/28/20 4123/29/20 4383/30/20 446Name: 147, Length: 73, dtype: object這是蟒蛇代碼:import pandas as pdinp_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()有沒有辦法在輸出文件中將完整的原始行作為列獲?。恐x謝
1 回答

嗶嗶one
TA貢獻1854條經(jīng)驗 獲得超8個贊
我會使用顯示最大行數(shù),然后調(diào)用數(shù)據(jù)幀再次打印
pd.set_option('display.max_rows',999)
print (f)
添加回答
舉報
0/150
提交
取消