Python Pandas 或 Numpy 或 XArray 或?或 PHP,加载大型列表

问题描述 投票:0回答:0

我正在尝试加载一个大列表(字符串),然后创建另一个仅包含唯一值的列表。 到目前为止,即使是约 2500 万行和约 2.4GB 文件大小的“小型”测试也给我带来了麻烦。

Fyi 这台开发 PC(Windows)有 128GB 内存。

Python版本:

PYTHON 3.9.16 | packaged by conda-forge | (main, Feb  1 2023, 21:28:38) [MSC v.1929 64 bit (AMD64)]

  • 麻木的:
    numpy.core._exceptions._ArrayMemoryError: Unable to allocate 879. GiB for an array with shape (25263524,) and data type <U9335
  • 熊猫:
    <class 'numpy.ndarray'>, 24926966 URLs, done in 21.750 s, rss 4323MB / peak 5288MB
  • 我也找到了 XArray,但它也耗尽了内存,而且似乎还是基于 numpy:
    numpy.core._exceptions._ArrayMemoryError: Unable to allocate 879. GiB for an array with shape (25263524,) and data type <U9335

最终文件大约有 300-5 亿行,每个大约 20-50GB。 到目前为止,我认为只有 Pandas 能够做到这一点,或者也许不能......

同事建议使用 PHP 8.2 和 array_unique:

array, 24926966 URLs, done in 5.7644670009613 s, rss 3882MB / peak 6314MB

快得多,是的,但内存(峰值)使用表明它不适用于大文件。 在一个项目中同时使用两种不同的语言会很痛苦。

是否有任何其他 Python 包可以创建唯一列表?

也许我们可以创建一个 SQLite 数据库,从每一行创建一个散列并检查散列是否已经存在……这将需要永远。

感谢任何想法

python php pandas numpy python-xarray
© www.soinside.com 2019 - 2024. All rights reserved.