pandas get_group causes memory error

2019-08-16 03:35发布

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条回答
叼着烟拽天下
2楼-- · 2019-08-16 03:48

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
查看更多
登录 后发表回答