[問題] pandas輸出txt時小數末端0的處裡

看板Python作者 (阿偉)時間6年前 (2019/06/24 12:01), 編輯推噓3(303)
留言6則, 6人參與, 6年前最新討論串1/1
板上的各位大大好 小弟目前想用pandas進行一些excel檔案之處裡 我想把excel檔轉輸出成txt 利用下方語法輸出 df.to_csv('filename.txt',sep=' ',header=None,index=None) 輸出是沒什麼問題 但例如123.5500這種數值 在輸出時小數點的0會被省略 想請問大家,該如何做才能讓他保留小數末端的0呢 感謝各位不吝賜較! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.46.166 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1561348891.A.A65.html

06/24 12:18, 6年前 , 1F
decimal + str?
06/24 12:18, 1F

06/24 14:08, 6年前 , 2F
全部存string
06/24 14:08, 2F

06/24 18:48, 6年前 , 3F
存 str 或輸出再補0
06/24 18:48, 3F

06/24 22:12, 6年前 , 4F
存成str 然後用format
06/24 22:12, 4F

06/25 00:12, 6年前 , 5F
pandas 可以用float_format 看你覺得全部人幾位數
06/25 00:12, 5F

06/28 00:47, 6年前 , 6F
感謝大家的回覆唷 最後採取lemon 大的方法 可行
06/28 00:47, 6F
文章代碼(AID): #1T44iRfb (Python)
文章代碼(AID): #1T44iRfb (Python)