- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目睹了 PyCharm 的一些奇怪的运行时问题,这些问题在下面进行了解释。该代码已在具有 20 个内核和 256 GB RAM 的机器上运行,并且有足够的内存可用。我没有展示任何实际功能,因为这是一个相当大的项目,但我非常乐意根据要求添加详细信息。
简而言之,我有一个具有以下结构的.py
文件项目:
import ...
import ...
cpu_cores = control_parameters.cpu_cores
prng = RandomState(123)
def collect_results(result_list):
return pd.DataFrame({'start_time': result_list[0::4],
'arrival_time': result_list[1::4],
'tour_id': result_list[2::4],
'trip_id': result_list[3::4]})
if __name__ == '__main__':
# Run the serial code
st = starttimes.StartTimesCreate(prng)
temp_df, two_trips_df, time_dist_arr = st.run()
# Prepare the dataframe to sample start times. Create groups from the input dataframe
temp_df1 = st.prepare_two_trips_more_df(temp_df, two_trips_df)
validation.logger.info("Dataframe prepared for multiprocessing")
grp_list = []
for name, group in temp_df1.groupby('tour_id'): ### problem lies here in runtimes
grp_list.append(group)
validation.logger.info("All groups have been prepared for multiprocessing, "
"for a total of %s groups" %len(grp_list))
################ PARALLEL CODE BELOW #################
for 循环 在 1050 万行和 18 列的数据帧上运行。在当前表单中,创建群组列表(280 万个群组)大约需要 25 分钟。这些组被创建,然后被提供给多进程池,其代码未显示。
它花费的 25 分钟相当长,因为我也完成了以下测试运行,只需要 7 分钟。本质上,我将 temp_df1 文件保存为 CSV,然后在预先保存的文件中进行批处理并运行与之前相同的 for 循环。
import ...
import ...
cpu_cores = control_parameters.cpu_cores
prng = RandomState(123)
def collect_results(result_list):
return pd.DataFrame({'start_time': result_list[0::4],
'arrival_time': result_list[1::4],
'tour_id': result_list[2::4],
'trip_id': result_list[3::4]})
if __name__ == '__main__':
# Run the serial code
st = starttimes.StartTimesCreate(prng)
temp_df1 = pd.read_csv(r"c:\\...\\temp_df1.csv")
time_dist = pd.read_csv(r"c:\\...\\start_time_distribution_treso_1.csv")
time_dist_arr = np.array(time_dist.to_records())
grp_list = []
for name, group in temp_df1.groupby('tour_id'):
grp_list.append(group)
validation.logger.info("All groups have been prepared for multiprocessing, "
"for a total of %s groups" %len(grp_list))
问题那么,是什么导致代码在我只批处理文件时比文件作为更上游函数的一部分创建时运行速度快 3 倍?
提前致谢,请告诉我如何进一步澄清。
最佳答案
我正在回答我的问题,因为我在进行大量测试时偶然发现了答案,幸运的是,当我用谷歌搜索解决方案时,其他人也有相同的 issue .在上面的链接中可以找到为什么在执行 group_by 操作时使用分类列不是一个好主意的解释。因此,我不打算在这里发布它。谢谢。
关于Python:Pycharm 运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51129600/
我知道可以在类型前添加#noinspection PyPep8Naming,但我想不通如何为单个文件全局设置。 我发现此功能适用于 some other JetBrains IDEs , 但未能在 P
我认为,在 PyCharm 的模块中重构函数名称通常会在项目范围内重构对该函数名称的任何使用。但是,我注意到项目中的笔记本中的功能没有被重构。重构时有没有办法包含笔记本? 我注意到 jupyter n
我需要使用 HTMLTestRunner 生成测试报告,因为该代码(位于文件末尾)是: suite = unittest.TestLoader().loadTestsFromTestCase(Test
Local History 是 Jetbrains IDE 系列(包括 Pycharm)绝对基础/关键的功能。为什么 .ipynb 文件会丢失?这是右键单击/上下文菜单 - 其中缺少 Show His
正如问题所问,如何在整个项目中的pycharm中运行查找/替换单词? 最佳答案 Edit | Find | Replace in Path。 快捷方式:Ctrl + Shift + R 关于pycha
我最近从 Spyder 更改为 PyCharm 作为 Python IDE。在 Spyder 中,我经常使用变量资源管理器功能(见图)。 PyCharm 中也提供此功能吗? 我找到了这个here ,“
嗨,我正在使用 pycharm 进行 python 开发。在 pycharm 中打开我的 python 项目时,它的打开方式如下图所示,其中我的项目名称是election,在此之前出现的选项卡都是父目
在 PyCharm 中,我的项目窗口中有一个文件夹是红色的。当所有其他文件夹都是蓝色时,该颜色意味着什么?我在 Git 中有我的项目,它主要是 Python,在 repo 中有一个 Java GUI。
我在我的 PyCharm 项目/文件栏中看到了这个: 我不确定这意味着什么,也不知道我为什么要这么做。谷歌搜索似乎没有提供任何有用的信息。有谁知道它是什么以及如何删除它?此外,项目中没有其他数字(没有
似乎 Pycharm 中的折叠自定义区域在某些缩进级别后不起作用。 这个不起作用: def test_a(): def function(): for g in group:
每当我创建一个函数、将其设为 View 并将模板映射到其上时,PyCharm 中的自动完成功能都会起作用。如果您输入类似 {{ book. }},其中 book 是一个模型,并且是您的上下文对象之一,
很长一段时间以来,我一直在寻找一种在 PyCharm 中折叠评论的方法。基本上我一直在寻找一种方法来实现与代码块相同的 + 注释。 最佳答案 用很容易做到这一点 #region Description
我正在使用 PyCharm 社区版 2016,我注意到我无法打开大数据输入文件或日志 (20MB)。编辑器只是说“文件 XXX 太大 (SIZE)”。 不仅如此,似乎也没有办法改变极限。官方文档提到了
在 PyCharm 中,我的项目窗口中有一个文件夹是红色的。当所有其他文件夹都是蓝色时,该颜色意味着什么?我在 Git 中有我的项目,它主要是 Python,在 repo 中有一个 Java GUI。
我想为 Pycharm 中的每个项目使用单独的虚拟环境。为此,我为每个项目创建了一个虚拟环境。我找不到清晰的文档 如果我想通过 PIP 命令添加或删除内容时需要为每个项目激活/停用这些虚拟环境,或者在
PyCharm 中是否有智能区分大小写搜索? 过去,我使用了一个编辑器,如果我使用小写字母,它会进行不区分大小写的搜索。 一旦我使用了第一个大写字符,搜索就区分大小写。 我喜欢这个。 我可以在 PyC
我已经按照 https://www.jetbrains.com/help/pycharm/requirements-installation-and-launching.html#linux 上的说明
有什么问题? 我在 PyCharm(版本 2016.1.4)中使用远程解释器(不是调试服务器!)进行远程调试,如下所述:jetbrains website . 当我在 Debug模式下运行时,程序会在
tldr;我希望我可以进入一个特定的程序状态,然后停止,然后继续编辑同一个文件,并使用这个过程迭代地向文件添加代码。 详情: 我经常想做的是使用python控制台或者在特定的程序状态下运行一段特定的代
有没有办法选择 PyCharm 中当前选定行下方的所有行(类似于在 Mac 中您可以使用 Cmd + Shift + down 选择行)? Cmd + Shift + right/left 工作正常,
我是一名优秀的程序员,十分优秀!