gpt4 book ai didi

python - 如何使用 Tkinter 导入索引列为 "date"的 csv 文件

转载 作者:太空宇宙 更新时间:2023-11-03 20:46:17 25 4
gpt4 key购买 nike

我想使用 Tkinter 导入 csv 文件。

我有以下代码:

df = pd.read_csv("KLBJ2.csv",
header=0,
index_col='Date of removal',
parse_dates=True)

df = df[['Price']]

我似乎无法理解如何将这段代码转换为使用 Tkinter 按钮的代码,该按钮导入 csv 文件,其中 index_col 为日期,然后使用该 CSV 文件中的数据保存在变量中。

谁能启发我吗?

最佳答案

您可以在按钮单击时使用回调方法,该方法将调用上面的代码段。示例代码看起来像这样。

b = Button(self, text="import csv", anchor = NW, relief=RAISED)
b.configure(command=self.import_csv_fun, width=8, activebackground="#33B5E5")

def import_csv_fun(self, widget):
"""imports the csv file"""
df = pd.read_csv("KLBJ2.csv",
header=0,
index_col='Date of removal',
parse_dates=True)

df = df[['Price']]

您可以按照您想要的方式操作df!

关于python - 如何使用 Tkinter 导入索引列为 "date"的 csv 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56580372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com