是什么导致使用fillna()时出现python内存错误

2024-10-01 11:41:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到以下错误

numpy.core._exceptions.MemoryError: Unable to allocate array with shape (1329, 22474) and data type float64

这是我的代码:

interactions_df = pd.DataFrame(list(DB[USER_COLLECTION].find({})))
interactions_full_df = interactions_df.groupby(['personId', 'contentId'])[
    'eventStrength'].sum().apply(smooth_user_preference).reset_index()
users_items_pivot_matrix_df = interactions_full_df.pivot(index='personId',  # edited: interactions_train_df
                                                         columns='contentId',
                                                         values='eventStrength').fillna(0)
users_items_pivot_matrix = users_items_pivot_matrix_df.as_matrix()
users_ids = list(users_items_pivot_matrix_df.index)

在{}中,我有30009个 文档和4列:_id, personId(string), eventStrength(double), contentId(int32),我试图通过设置来增加ram,但没有效果,仍然无法解决

更新: 将windows上的自定义虚拟内存设置为最大内存80000 MB和初始大小5500 MB,并重新启动系统后,仍然存在内存错误


Tags: 内存dfindex错误itemsmbusersmatrix