pandas - Tkinter Scale 以将值输入到 pandas dataframe.head
问题描述
我正在尝试使用 Tkinter 的 Scale 小部件将值传递给应该修改 pandas dataframe.head() 值的函数。例如,如果 Tkinter 比例设置为 50,则传递给 .head 方法的值应如下所示:dataframe.head(50)。
我的代码如下所示:
def scatterplot(value):
try:
global graph
global bar_chart_df
global clean_df
global correlation
correlation = clean_df.groupby(['FACILITY ZIP', 'FACILITY NAME'])['VIOLATION DESCRIPTION'].count().reset_index(name='No. Violations').sort_values(by='No. Violations', ascending=False)
hue = correlation["FACILITY NAME"].head(value)
y = correlation["FACILITY ZIP"].head(value)
x = correlation["No. Violations"].head(value)
sns.scatterplot(x, y, hue)
plt.title('Correlation between the number of violations committed per vendor and their zip code (sample of 150)')
plt.legend(loc='upper right')
plt.figure(figsize=(30, 45), dpi=300, facecolor='w', edgecolor='k')
plt.tight_layout()
plt.show()
except:
my_error = tk.messagebox.showerror(title="Try again", message="Please load a valid dataset")
cmd_frame_3 = ttk.LabelFrame(self.window, text="Statistics", relief=tk.RIDGE)
cmd_frame_3.grid(row=2, column=2, sticky=tk.E + tk.W + tk.N + tk.S, padx=6)
my_scale = tk.Scale(entry_frame, from_=0, to=100, command=scatterplot, orient=tk.HORIZONTAL, width=8, length=200)
my_scale.grid(row=4, column=2, sticky=tk.W)
由于某种原因,它不起作用并显示此错误:
相关性 = clean_df.groupby(['FACILITY ZIP', 'FACILITY NAME'])['VIOLATION DESCRIPTION'].count().reset_index(name='No. Violations').sort_values(by='No. Violations',升序=假)
NameError:名称“clean_df”未定义
Tkinter 回调 Traceback 中的异常(最近一次调用最后一次):
文件“/opt/anaconda3/lib/python3.8/tkinter/init .py ”,第 1883 行, 调用中 返回 self.func(*args)
我没看到什么?
解决方案
推荐阅读
- javascript - 在动态创建的元素上添加相同的事件监听器?
- python - 对客户交易数据进行傅里叶分析的建议
- r - 根据值和最早日期选择唯一行并保留所有列,R
- python - 如何用张量流计算向量函数的雅可比行列式
- php - pdf文件的TCPDF未知高度
- json - 如何从
- windows - WES7 没有 'CHOICE' 。我有哪些选择?
- rust - Rust 中枚举的展平向量
- javascript - 如何通过 {{{ }}}(模板助手)将操作绑定到 ember 模板中的标记?
- json - 如果 API 响应是 Ionic + Angular 中的字符串而不是 JSON,如何处理