我正在嘗試更改從 SQL 查詢創建的 CSV 檔案上列印的名稱。我希望檔案名看起來像這個 yyyyddmm_"name"。使用年日月捕獲其創建日的相應日期。目前我正在使用熊貓和日期時間,這并沒有給我正確的名稱結構。你能推薦一個替代方案嗎?感謝您對此事的幫助。干杯。
df.to_csv(r datetime.now()"Name Name" ".csv", index=False)
uj5u.com熱心網友回復:
import time
file_name = time.strftime("%Y%m%d" "_Name")
print(file_name)
對于你的情況
import time
file_name = time.strftime("%Y%m%d" "_Name")
save_to_path = r'C:\Users\MyPC\Desktop' #this is where your .csv file will be saved
df.to_csv(save_to_path "\\" file_name ".csv", index=False)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/531761.html