pandas get_group causes memory error

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 23:13:38

问题


I have a grouped dataframe created like so:

my_gb = pandas.read_csv(filepath_or_buffer=my_file_path,
                        delimiter='\t').groupby(['col1', 'col2', 'col3', 'col4'])

I then call get_group:

my_row = my_gb.get_group((val1, val2, val3, val4))

And get a MemoryError.

IIUC, this only returns a view of one row (in my dataset) - how can this cause a memory error?


回答1:


Couldn't get this to work so I did the grouping myself:

data = pandas.read_csv(filepath_or_buffer=my_file_path, delimiter='\t')
grouped = {}
for key, value in data.iterrows():
    grouped[(value['col1'], value['col2'], value['col3'], value['col4'])] = value


来源:https://stackoverflow.com/questions/28263073/pandas-get-group-causes-memory-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!