Library for Standardizing names from a Pandas dataframe
Project description
Similar Names
Library for Standardizing names from a Pandas dataframe
Description
Similar Names is basically a package for names manipulation. That is, if you have a Pandas dataframe with multiple names written in different ways (e.g.: John Doe, John E. Doe and John Edson Doe), the "closeMatches" function will look for all similar names on that column and then add two columns: "Close Matches" (list of all close matches) and "StandardName" (shortest name of the list).
Instalation
Similar Names can be installed directly through pip
pip install similarnames
How to use?
If you have a pandas dataframe with the names that you want to standardize, or look for close matches, simply follow the steps described next. As for the "closeMatches" parameters, they are basically 6:
closeMatches(obj, names, sep = ',', connectors = ['and','e','y'], languages = ['english', 'portuguese', 'spanish'], customWords = None)
- obj (dataframe): The pandas dataframe
- names (str): The name of the pandas dataframe with the names that you want to analyze
- sep (str or None): The separator to be used to split multiple names
- connectors (str, list or None): Words to also be used as separators (e.g.: "and")
- languages (str, list or None): Lanaguages for the default stopwords config (All stopwords are not considered names)
- customWords (str, list or None): Additional words that should not be considered as names (e.g.: "jr")
1st Scenario: 1 name per row
In case your dataframe is already formatted with one name per row, simply execute the following command setting the "sep" parameter to "None". In case you are having some trouble with the results, you can set the "languages" and "customWords" parameters to include, or exclude, names from the analyses (by default, stopwords in english, portuguese and spanish are not considered names).
'''
Input (df): df and the name of the column with the names to check
| Names | ... |
|----------------|-----|
| John Doe | |
| John Edson Doe | |
| John E. Doe | |
| John Edson D. | |
'''
from similarnames import closeMatches
# Default config: sep = ',', connectors = ['and','e','y'], languages = ['english', 'portuguese', 'spanish'], customWords = None
df_standard = closeMatches(df, 'Names', sep = None)
'''
Output (df_standard)
| Names | ... | CloseMatches | StandardName |
|----------------|-----|----------------------------------------------------------------|--------------|
| John Doe | | ['John Doe', 'John E. Doe', 'John Edson Doe', 'John Edson D.'] | John Doe |
| John Edson Doe | | ['John Doe', 'John E. Doe', 'John Edson Doe', 'John Edson D.'] | John Doe |
| John E. Doe | | ['John Doe', 'John E. Doe', 'John Edson Doe', 'John Edson D.'] | John Doe |
| John Edson D. | | ['John Doe', 'John E. Doe', 'John Edson Doe', 'John Edson D.'] | John Doe |
'''
2nd Scenario: Multiple names per row
In case you have multiple names in a single row, the "explode" is automatically done for you. So, just provide the "sep" parameter to identify where we should use to split those names. By default, the connectors "and", "e" and "y" will also be considered as separators. Therefore, in case you are working in a different language, just set the "connectors" and "languagues" parameter as you wish.
'''
Input (df): df and the name of the column with the names to check
| Names | Other columns | ... |
|----------------------------------------------|-------------------------|-----|
| John Doe, Jane Doe | Two names (sep = ',') | |
| John E. Doe and Michael Johnson | Two names (without sep) | |
| Jane A. Doe, Michael M. Johnson and John Doe | Three names (sep = ',') | |
'''
from similarnames import closeMatches
# Default config: sep = ',', connectors = ['and','e','y'], languages = ['english', 'portuguese', 'spanish'], customWords = None
df_standard = closeMatches(df, 'Names', sep = ',')
'''
Output (df_standard)
| Names | Other columns | ... | CloseMatches | StandardName |
|--------------------|-------------------------|-----|-------------------------------------------|-----------------|
| John Doe | Two names (sep = ',') | | ['John Doe', 'John E. Doe'] | John Doe |
| Jane Doe | Two names (sep = ',') | | ['Jane Doe', 'Jane A. Doe'] | Jane Doe |
| John E. Doe | Two names (without sep) | | ['John Doe', 'John E. Doe'] | John Doe |
| Michael Johnson | Two names (without sep) | | ['Michael Johnson', 'Michael M. Johnson'] | Michael Johnson |
| Jane A. Doe | Three names (sep = ',') | | ['Jane Doe', 'Jane A. Doe'] | Jane Doe |
| Michael M. Johnson | Three names (sep = ',') | | ['Michael Johnson', 'Michael M. Johnson'] | Michael Johnson |
| John Doe | Three names (sep = ',') | | ['John Doe', 'John E. Doe'] | John Doe |
'''
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
Built Distribution
File details
Details for the file similarnames-0.1.5.tar.gz
.
File metadata
- Download URL: similarnames-0.1.5.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.8.8 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b90e1a1595961a15b617db5c7d55b3df63dea03abdd87aabe245bab8e0f07a2 |
|
MD5 | b2969b6483969746973ed3348c176af8 |
|
BLAKE2b-256 | 64cb40ab5dafdc54144f85a99871427506be2b1538d4c063e6f8232e064824e8 |
File details
Details for the file similarnames-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: similarnames-0.1.5-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.8.8 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a315c62dc6818305afdc37af16272ded925a59381674e6be9c59e74c80694fa |
|
MD5 | 9f258ed1ebd563d133988e184e3f5b37 |
|
BLAKE2b-256 | 1d44bbaefa4fb72e77c6e9f8edf6523111345a7521ce4bb499afe66324994021 |