How to concatenate multiple pandas.DataFrames without running into MemoryError

后端 未结 10 1299
盖世英雄少女心
盖世英雄少女心 2020-12-24 12:19

I have three DataFrames that I\'m trying to concatenate.

concat_df = pd.concat([df1, df2, df3])

This results in a MemoryError. How can I re

10条回答
  •  生来不讨喜
    2020-12-24 13:08

    You can store your individual dataframes in a HDF Store, and then call the store just like one big dataframe.

    # name of store
    fname = 'my_store'
    
    with pd.get_store(fname) as store:
    
        # save individual dfs to store
        for df in [df1, df2, df3, df_foo]:
            store.append('df',df,data_columns=['FOO','BAR','ETC']) # data_columns = identify the column in the dfs you are appending
    
        # access the store as a single df
        df = store.select('df', where = ['A>2'])  # change where condition as required (see documentation for examples)
        # Do other stuff with df #
    
    # close the store when you're done
    os.remove(fname)
    

提交回复
热议问题