作者:客户服务部小谢娟_387 | 来源:互联网 | 2023-08-27 21:40
data = pd.read_csv('./x1.csv', names=['0','1','2','3','4','5','6','7','8','9'])
x = data['2']
y = data['3']
z = data['4']
u = data['6']
w = data['7']
这段代码如果通过GUI实现,如何做?谢谢!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| import tkinter as tk
from tkinter.filedialog import askopenfilename
import pandas as pd
import csv
root = tk.Tk()
root2 = tk.Tk()
def import_csv_data():
global v
csv_file_path = askopenfilename()
print(csv_file_path)
v.set(csv_file_path)
# df = pd.read_csv(csv_file_path)
newfile = pd.read_csv(csv_file_path,encoding="gbk") # 读的时候设置格式
colist=newfile.columns
newfile = newfile[colist]#colist是一个列表,里边存放的是列名入['a','b','c']
tpframe2 = tk.Frame(root2)
tpframe2.pack(fill=tk.BOTH)
s2 = tk.Scrollbar(tpframe2, orient=tk.VERTICAL)
s2.pack(side=tk.RIGHT, fill=tk.Y)
# 显示文本内容组件
text1 = tk.Text(tpframe2, height=600, yscrollcommand=s2.set)
text1.pack(fill=tk.BOTH)
s2.config(command=text1.yview)
text1.insert(tk.INSERT,newfile)
tk.Label(root, text='File Path').grid(row=0, column=0)
v = tk.StringVar()
entry = tk.Entry(root, textvariable=v).grid(row=0, column=1)
tk.Button(root, text='Browse Data Set',command=import_csv_data).grid(row=1, column=0)
tk.Button(root, text='Close',command=root.destroy).grid(row=1, column=1)
root.mainloop() |
是这样吗?要设置文件格式为gbk或者utf-8之类的