1

I am trying to save the excel file as a .xlsx file then I want to import that new file back into python using pandas and numpy to allow for statistical analysis. I want the USER to have the option of where to save the file with the 'asksaveasfile' and another dialog box 'askopenwhen opening the file for pandas and numpy. Also, if someone can show how to convert specific columns from bytes to str. See below... TypeError: write() argument must be str, not bytes. Here's the end of the code:

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))
  • Welcome to Stackoverflow! Have you tried https://stackoverflow.com/questions/40389764/how-to-translate-bytes-objects-into-literal-strings-in-pandas-dataframe-pytho ? – francis Jan 10 '20 at 22:52
  • always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Jan 12 '20 at 12:07
  • `--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) in 78 import os 79 import tkinter as tk 80 from tkinter import filedialog 81 82 fn = filedialog.asksaveasfile(mode='w', defaultextension=".xlsx") ~\AppData\Local\Continuum\anaconda3\lib\tkinter\filedialog.py in 15 from tkinter import * 16 from tkinter.dialog import Dialog 17 from tkinter import commondialog ModuleNotFoundError: No module named 'tkinter.dialog'` – Paul Trovato Jan 13 '20 at 15:14

0 Answers0