熊猫和Tkinter,打开和保存文件

时间:2020-01-10 20:33:57

标签: python pandas dataframe tkinter

我正在尝试将excel文件另存为.xlsx文件,然后我想使用pandas和numpy将新文件导入回python中,以进行统计分析。 我希望用户在打开pandas和numpy文件时,可以选择使用“ asksaveasfile”和另一个对话框“ askopen”将文件保存在何处。 另外,如果有人可以展示如何将特定的列从字节转换为str。见下文... TypeError: write() argument must be str, not bytes. 这是代码的结尾:

import csv
import pandas as pd
import os
import tkinter as tk
from tkinter import filedialog

fn = filedialog.asksaveasfile(mode='w', defaultextension=".xlsx")
result = pdf_to_csv(fn)

lines = result.split('\n')
import openpyxl as pxl
wb = pxl.Workbook(fn)
ws = wb.active
for line in lines:
    ws.append(line.split(';'))
    # appending a list gives a complete row in xlsx

print("Successfully Saved! ")

root = tk.Tk()
root.withdraw()
dataFile=pd.read_excel(fn)#,usecols=['Last Name','First Name','Assignment Title','Department Code','Calendar Year', 'Compensation'])

dataFile.to_excel(fn)
print(fn)

df = fn
DataFrame = df
df1 = DataFrame
df1.columns = ['Last Name','First Name','Assignment Title','Department Code','Calendar Year', 'Compensation']
df1.drop(df1.index[0], inplace=True)
print(df1.head(11))

0 个答案:

没有答案