【问题标题】:How to detect that large pandas dataframe has different data then before如何检测大熊猫数据框的数据与以前不同
【发布时间】:2021-05-06 14:03:59
【问题描述】:

我使用 pandas 处理大于 1GB 的大型 csv 文件。该脚本应检测数据框中的数据是否与之前运行的数据不同。我无法存储过去的数据框。 我正在寻找从 pandas 数据帧返回一种哈希值的快速函数。这样我就可以只存储和比较那些“类似哈​​希”的值。

【问题讨论】:

    标签: python pandas large-data


    【解决方案1】:
    import joblib
    joblib.hash(df)
    

    这应该可以吗?

    这个未记录的哈希也存在于pandas 20.1

    from pandas.util import hash_pandas_object
    h = hash_pandas_object(df)
    

    如果您想要一个整体价值而不是像hash_pandas_object 返回的每个系列,只需调用.sum()

    【讨论】:

    • joblib.hash(df) 对我不起作用,因为 hash(df.copy()) != hash(df)。 hash_pandas_object(df.copy()) == hash_pandas_object(df) - 这样更好!
    猜你喜欢
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 2020-11-24
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    • 2019-07-08
    • 2013-06-23
    相关资源
    最近更新 更多