我正在尝试从输入csv文件保存我的数据并将其写入另一个csv文件。我知道如何使用to_csv方法编写dataFile并使用预先确定的文件写入(output.csv)。我如何通过asksaveasfile对话框方法完成。任何帮助表示赞赏。
import csv
import pandas as pd
import os
import tkinter as tk
from tkinter import filedialog
SAVING_PATH = 'C:/Users/Desktop/'
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
dataFile=pd.read_csv(file_path,usecols=['Name','Email','Gender'])
dataFile.to_csv(os.path.join(SAVING_PATH,r'output.csv'))
dataFile = filedialog.asksaveasfile(mode='w', defaultextension=".csv")
答案 0 :(得分:2)
没关系我已经修好了问题。
import csv
import pandas as pd
import os
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
dataFile=pd.read_csv(file_path,usecols=['Name','Email','Gender'])
SAVING_PATH = filedialog.asksaveasfile(mode='w', defaultextension=".csv")
dataFile.to_csv(SAVING_PATH)