我编写了一个适用于 csv 文件的代码,但是如果我将文件类型从 csv 更改为 excel,它会给我一个错误。
我有,data = pd.read_excel(filename)如果我写,上面的行不适用于excel data = pd.read_csv(filename),它工作正常。我希望我在 excel 中的输入数据不是 csv。
import tkinter as tk
import pandas as pd
from tkinter.filedialog import askopenfilename
import xlrd
def latlong_func(filename):
# filename instead of r'C:/Users/patesari/Desktop/python work/Gap1.csv'
data = pd.read_excel(filename)
#df = pd.DataFrame(data, columns=['SUPPLIER_ID','ACTION'])
data["latlong"] = 'FALSE'
data.loc[
(data["LONGITUDE"] >= 70.0000) & (data["LONGITUDE"] <= 98.0000) &
(data["LONGITUDE"] != 'nan') & (data["LATITUDE"] != 'nan')&
(data["LATITUDE"] >= 6.0000) & (data["LATITUDE"] <= 36.000),
["latlong"]] = ''
data.to_csv("practice1.csv")
writer = data[data["latlong"]=='']
writer.to_csv('newfile1.csv')
writer.to_csv('latlong1.csv')
print("Kindly ignore the message..your output is genrated sucessfully....")
def get_filename():
filename = askopenfilename(filetypes =[('Python Files', '*.xlsx')])
if filename:
lbl['text'] = filename # display filename in Label
latlong_func(filename)
else:
lbl['text'] = 'not selected'
# --- main ---
root = tk.Tk()
root.geometry('200x100')
lbl = tk.Label(root, text='Select filename')
lbl.pack(side='top', pady=10)
btn = tk.Button(root, text='Open', command=get_filename)
btn.pack(side='top', pady=10)
root.mainloop()
有人请帮助我知道我在哪里做错了。
德玛西亚99
潇湘沐
相关分类