`DataFrame` 行的内存高效过滤 [英] Memory-efficient filtering of `DataFrame` rows

查看:40
本文介绍了`DataFrame` 行的内存高效过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的 DataFrame 对象(1,440,000,000 行).我在内存(交换包括)限制下操作.

我需要提取具有特定字段值的行的子集.但是,如果我喜欢那样:

<预><代码>>>>SUBSET = DATA[DATA.field == value]

我以 MemoryError 异常或崩溃结束.有什么方法可以显式过滤行 - 无需计算中间掩码(DATA.field == value)?

我找到了 DataFrame.filter()DataFrame.select() 方法,但它们对列标签/行索引而不是行数据进行操作.

解决方案

使用 query,应该会快一点:

df = df.query("field == value")

I have a large DataFrame object (1,440,000,000 rows). I operate at memory (swap includet) limit.

I need to extract a subset of the rows with certain value of a field. However if i do like that:

>>> SUBSET = DATA[DATA.field == value]

I end with either MemoryError exception or crash. Is there any way to filter rows explicitely - without calculating intermediate mask (DATA.field == value)?

I have found DataFrame.filter() and DataFrame.select() methods, but they operate on column labels/row indices rather than on the row data.

解决方案

Use query, it should be a bit faster:

df = df.query("field == value")

这篇关于`DataFrame` 行的内存高效过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆