df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
fileName = QFileDialog.getSaveFileName(self,"Save",os.getcwd(),"CSV Files (*.csv)")
if fileName:
with open(fileName, "w") as file:
file.write(df)
我正在尝试使用QFileDialog而不是df.to_csv将数据帧保存到csv,但这不起作用
答案 0 :(得分:0)
fileName = QFileDialog.getSaveFileName(self,"Save",os.getcwd(),"CSV Files (*.csv)")
print(fileName)
这将返回元组中的字符串,首先是路径
您应该写:
fileName, _ = QFileDialog.getSaveFileName(self,"Save",os.getcwd(),"CSV Files (*.csv)")