Python中文
首页
教程
问答
标签
搜索
登录
注册
python 3中非常慢的循环,tkinter
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在用一个界面编写一些脚本,我遇到了一些性能非常差的问题</p> <p>我想为每一列(129)创建多个条目,列应该是7。为此,我创建了一个字典,因此使用动态变量名创建了空条目</p> <p>对于这些空条目,我希望根据特定单元格(国家/地区)中提供的内容插入文本</p> <p>任务已经完成,但是,加载数据需要花费大量的时间,我不知道可以做些什么来加快加载速度。。我不能让它这么慢,尤其是在项目的这个阶段</p> <p><strong>从提取文件获取信息的函数:</strong></p> <pre><code>def Load_Neighborhood_Details(self, inx, what_return): file_path = r'C:\Users\krzysztof-wirkus\Desktop\Od nowa\extracts\neighborhood_details.csv' file = pd.read_csv(file_path, encoding = "ISO-8859-1") country = file[file['Country Name'] == self.p0.country_input.get()] location = country[country['Location Name'] == self.p0.location_input.get()].iloc[inx] neighborhood_name = location['Neighborhood Name'] dwelling = location['Dwelling'] furniture = location['Furnished Unfurnished Indicator'] item_cost_category = location['Item Cost Category Name'] neigh_class = location['Class'] try: start_date = location['Start Date'].split()[0] except: start_date = "" try: end_date = location['End Date'].split()[0] except: end_date = "" if what_return == "neighborhood_name": return neighborhood_name elif what_return == "dwelling": return dwelling elif what_return == "furniture": return furniture elif what_return == "item_cost_category": return item_cost_category elif what_return == "neigh_class": return neigh_class elif what_return == "start_date": return start_date elif what_return == "end_date": return end_date </code></pre> <p><strong>我糟糕的性能循环:</strong></p> <pre><code>for i in range(2, 131): self.p3.dict['neighborhood_details_name_entry_' + str(i)].insert(tk.END, self.Load_Neighborhood_Details(i-2, "neighborhood_name")) self.p3.dict['neighborhood_details_dwelling_entry_' + str(i)].insert(tk.END, self.Load_Neighborhood_Details(i-2, "dwelling")) self.p3.dict['neighborhood_details_furniture_entry_' + str(i)].insert(tk.END, self.Load_Neighborhood_Details(i-2, "furniture")) self.p3.dict['neighborhood_details_item_cost_category_entry_' + str(i)].insert(tk.END, self.Load_Neighborhood_Details(i-2, "item_cost_category")) self.p3.dict['neighborhood_details_class_entry_' + str(i)].insert(tk.END, self.Load_Neighborhood_Details(i-2, "neigh_class")) self.p3.dict['neighborhood_details_start_date_entry_' + str(i)].insert(tk.END, self.Load_Neighborhood_Details(i-2, "start_date")) self.p3.dict['neighborhood_details_end_date_entry_' + str(i)].insert(tk.END, self.Load_Neighborhood_Details(i-2, "end_date")) </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您的代码的性能非常差,因为您要多次打开csv文件,您应该只打开一次(如果可能)并将其作为函数的参数传递,这将有助于提高性能</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
使用Python创建一个非常大的二进制频率矩阵来运行协作过滤
10 回答
使用Python创建一张HTML网页,其中在不同颜色中重复n遍显示“Hello World”的方法
9 回答
使用Python创建一组唯一的值length L
3 回答
使用python创建不同表格的透视表
9 回答
使用python创建不和谐频道
7 回答
使用python创建不存在的多个文件夹
8 回答
使用python创建串行远程文件
3 回答
使用python创建交互式仪表板时出现问题
1 回答
使用python创建交互式绘图
5 回答
使用python创建交互式自动电子邮件
7 回答
使用Python创建价格列表
4 回答
使用python创建修改的txt文件
4 回答
使用Python创建全局变量,初始化后更改值
8 回答
使用Python创建关键字搜索词数组
6 回答
使用Python创建具有不均匀块大小/堆叠条形图的热图
1 回答
使用Python创建具有依赖于另一列的值的列
1 回答
使用Python创建具有多列的HTML表
10 回答
使用Python创建具有时间范围数据的等距数据帧
4 回答
使用Python创建具有特定顺序或属性的XML文件
9 回答
使用Python创建具有级联功能的搜索栏
3 回答