Skip to main content

Makes unhashable values in a pandas DataFrame hashable

Project description

hashable_df

If you have ever tried to use native python objects in Pandas DataFrames, you may have run into an issue similar to this:

df = pd.DataFrame({"A": [1, 2, 3, 4],
                   "B": ["a", "b", "c", "d"],
                   "C": [[1, 2, 3], [1, 2], [1, 2, 3], 4],
                   "D": [{1: 1, 2: 2}, {1: 1, 3: 3}, {1: 1, 4: 4}, {1: 1, 2: 2}],
                   "E": [[{1: {2: 2}}, {2: {3: 3}}], [{1: {2: 2}}, {2: {3: 3}}],
                         [{1: {2: 2}}, {2: {3: 3}}], [{1: {2: 2}}, {2: {3: 3}}]]
                   })
df['C'].unique()

TypeError: unhashable type: 'list'

This is caused by unhashable values in the DataFrame cells.

This small library helps to resolve that making this possible:

from hashable_df import hashable_df
hashable_df(df)['E'].unique()

returning

array([[{1: {2: 2}}, {2: {3: 3}}]], dtype=object)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hashable_df-0.0.8.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

hashable_df-0.0.8-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file hashable_df-0.0.8.tar.gz.

File metadata

  • Download URL: hashable_df-0.0.8.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for hashable_df-0.0.8.tar.gz
Algorithm Hash digest
SHA256 cde2fe6adea96a030507f7b7770332ac6d6a5770c55d30bb355199401272a545
MD5 308e403a52e0fbb7b9425fd98b247e25
BLAKE2b-256 8d03b21249e806969ed6d82985b5c721392f839ab4caba91c8781014740e97f6

See more details on using hashes here.

File details

Details for the file hashable_df-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: hashable_df-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for hashable_df-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0f8ed9603f3e6f5a1e70a5b56b27a89b1a401e5ef19146b05063045e9b34573a
MD5 3796c71b5b770ee3c6ad57b842321a86
BLAKE2b-256 dd1411caab481d9d5dcb039d381dc615eab88d1281a180778185f7c511f19f14

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page