【问题标题】:Memory issue when handling huge dataframe and transpose it in Python 2.7处理巨大数据帧并在 Python 2.7 中转置时的内存问题
【发布时间】:2020-10-03 17:53:39
【问题描述】:

我有一个大约 400k - 700k 行和 ~700 列的数据框。数据框需要转置,这意味着只有 10 列固定,其余的需要从列更改为行。我不是在这里要求换位逻辑。我知道该怎么做,但是在执行转置操作时遇到了内存错误。我尝试分批执行操作,但这需要很多时间。我想使用 ProcessPoolExecuter。

#df - original df
list_df = [df.iloc[i:i+CHUNK_SIZE] for i in range(0, len(df), CHUNK_SIZE) ]
del df # just to free some memory 
gc.collect()
param_list = [(dummy_df, a, b, c) for dummy_df in list_df] #list of parameters to function
del list_df
gc.collect()
with ProcessPoolExecuter() as executer:
    results = executer.map(function_to_transpose_df, patam_list)
final_df = pd.concat(results )
del results
gc.collect()

#...

param_list 是函数的参数列表。我本可以将 *(dummy_df, a, b, c) 用于 Python 3.5,但是如何在 Python 2.7 中解包? executer.map(function_to_transpose_df, patam_list) 不会以当前形式工作。

【问题讨论】:

    标签: pandas python-2.7 dataframe


    【解决方案1】:

    您可以使用 hsplit 将数据拆分为块,然后执行 transponse,然后将数据附加回来......

    【讨论】:

    • 你能举个例子来支持一下吗?目前,它的级别非常高。
    猜你喜欢
    • 1970-01-01
    • 2019-11-14
    • 2018-09-15
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    相关资源
    最近更新 更多