我想將文本檔案轉換為 csv 檔案
import pandas as pd
readfile = pd.read_csv(r'text.txt')
readfile.to_csv(r'CSV.csv, index=None)
我的文本檔案格式:

結果:

在紅色圓圈中,它在重復的資料之后添加一個十進制數字我不希望它添加一個十進制數字
請建議我下一步該怎么做,謝謝。
如果可以讀取檔案并轉換為帶有限制列的 csv,請告知!
uj5u.com熱心網友回復:
#just add header = None, since first line of txt is considered header that's why it is managing duplicate column names.
import pandas as pd
readfile = pd.read_csv(r'text.txt',header=None)
readfile.to_csv(r'CSV.csv, index=None)
#sample example output of readfile
0 1 2 3 4 5 6 7 8
0 1 2 3 5 0.0 0.0 0.0 4 6
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/518158.html
標籤:Python熊猫CSV
