Skip to main content

Linking rows of pandas dataframes

Project description

# pandas-linker

`pandas-linker` runs comparison windows over pandas DataFrame and
links the rows via assigned UUIDs. This library does not actually do any duplicate
detection but provides a harness to run your own comparison functions on your data.


## Example

Let's say you have a DataFrame like this:

[ix] | name | country
------|------|--------
0 | Pete | Spain
1 | Mary | USA
2 | Bart | US
3 | Mary | US

and you want to detect similar rows and mark them as such. Here's how to that:

```python
from pandas_linker import get_linker


def compare_rows(a, b):
''' Example function that decides if two rows represent same entity.'''
return a['name'] in b['name'] or b['name'] in a['name']

# df is a pandas.DataFrame with a unique index

with get_linker(df, field='uid') as linker:

print('Comparing in 10 row window sorted by name')
linker(sort_cols=['name'], window_size=10, cmp=compare_rows)

print('Comparing in 15 row window sorted by country')
linker(sort_cols=['country'], window_size=15, cmp=compare_rows)

```

After running the linker the process is complete

[ix] | name | country | uid
------|------|---------|----
0 | Pete | Spain | 7509781940fc471cad5dc32944652d70
1 | Mary | USA | 8f8dccd91568472daf740e9160349d6c
2 | Bart | US | 12b55fbe80f64d378193acd727b0e051
3 | Mary | US | 8f8dccd91568472daf740e9160349d6c

Note that both "Mary" rows in the DataFrame have been identified as representing
the same entity and were assigned the same UUID.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pandas_linker-0.0.1-py2.py3-none-any.whl (5.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pandas_linker-0.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pandas_linker-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bf1f7026e1818ee4781e0498f610b79d8907873758026c3be0b8e527d9396d49
MD5 3a11fb2e6aac1c42eddd4097528f414a
BLAKE2b-256 10e29f7a502da4b5e5031a456ce84f90229ab6ad20922a61b182533913f17a7a

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