我想显示我的标签编码的结果,tkinter
就像我print
在 python 中使用函数显示它一样。
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df["REPORT_FAMILY"] = le.fit_transform(df["REPORT_FAMILY"])
print("Mapping: ")
for i, item in enumerate(le.classes_):
print(item, "-->", i)
此代码产生如下结果:
Mapping:
ADELBERT SC3000 --> 0
ADELBERT SC3020 --> 1
ALAR --> 2
ALTER EGO SC460 --> 3
ALTER EGO SCV360 --> 4
ARYA --> 5
BEACHCOMBER --> 6
我如何在 tkinter 中做同样的事情?我使用以下代码但收到错误。我的目标是将编码的 REPORT_FAMILY 列显示到 REPORT_FAMILY 中的相应类别。
import tkinter as tk
#creating the window
window = tk.Tk()
window.title("FPY+ Prediction")
canvas1 = tk.Canvas(window, width = 500, height = 300)
canvas1.pack()
t = tk.Text(window)
for i, item in enumerate(le.classes_):
t.insert(item, "-->", i)
t.pack()
window.mainloop()
我收到以下错误:
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-30-6c09ea2a9048> in <module>
11 canvas1.create_window(200, 300)
12 for i, item in enumerate(le.classes_):
---> 13 t.insert(item, "-->", i)
14 t.pack()
15
~\Anaconda3\lib\tkinter\__init__.py in insert(self, index, chars, *args)
3270 """Insert CHARS before the characters at INDEX. An additional
3271 tag can be given in ARGS. Additional CHARS and tags can follow in ARGS."""
-> 3272 self.tk.call((self._w, 'insert', index, chars) + args)
3273 def mark_gravity(self, markName, direction=None):
3274 """Change the gravity of a mark MARKNAME to DIRECTION (LEFT or RIGHT).
TclError: bad text index "ADELBERT SC3000"