小编Abi*_*san的帖子

使用 Tkinter GUI 中的 read_csv 打开并读取 csv 文件

from tkinter import filedialog, Label, Button, Entry, StringVar
from tkinter.filedialog import askopenfile
import pandas as pd

root = tk.Tk()
Label(root, text='File Path').grid(row=0, column=0)
v = StringVar()
entry = Entry(root, textvariable=v).grid(row=0, column=1)
Button(root, text='Browse Data Set',command=lambda:   v.set(askopenfile())).grid(row=1, column=0)
Button(root, text='Close',command=root.quit()).grid(row=1, column=1)
root.file = v.get()
df = pd.read_csv(root.file)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)

我想通过单击按钮打开数据集(CSV 文件)并使用 pd.read_csv()函数读取它,但我收到一些错误

Traceback (most recent call last):
  File "/home/abishek/PycharmProjects/untitled1/temp.py", line 21, in <module>
    df = pd.read_csv(root.file)
  File "/usr/lib/python3/dist-packages/pandas/io/parsers.py", line 498, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/usr/lib/python3/dist-packages/pandas/io/parsers.py", line 275, in _read …
Run Code Online (Sandbox Code Playgroud)

python tkinter

1
推荐指数
1
解决办法
3万
查看次数

标签 统计

python ×1

tkinter ×1