- Notifications
You must be signed in to change notification settings - Fork6
Python package to reconcile DataFrames
License
jvfe/reconciler
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
reconciler
is a python package to reconcile tabular data with various reconciliation services, such asWikidata, working similarly to whatOpenRefinedoes, but entirely within Python, using Pandas.
You can install the latest version of reconciler from PyPI with:
pip install reconciler
Then to use it:
fromreconcilerimportreconcileimportpandasaspd# A DataFrame with a column you want to reconcile.test_df=pd.DataFrame( {"City": ["Rio de Janeiro","São Paulo","São Paulo","Natal"],"Country": ["Q155","Q155","Q155","Q155"] })# Reconcile against type city (Q515), getting the best match for each item.reconciled=reconcile(test_df["City"],type_id="Q515")
The resulting dataframe would look like this:
id | match | name | score | type | type_id | input_value |
---|---|---|---|---|---|---|
Q8678 | True | Rio de Janeiro | 100 | city | Q515 | Rio de Janeiro |
Q174 | True | São Paulo | 100 | city | Q515 | São Paulo |
Q131620 | True | Natal | 100 | municipality of Brazil | Q3184121 | Natal |
In case you want to ensure the results are cities from Brazil, you can specify the property_mapping argument witha specific property-value pair:
# Reconcile against type city (Q515) and items have the country (P17) property equals to Brazil (Q155)reconciled=reconcile(test_df["City"],type_id="Q515",property_mapping={"P17":test_df["Country"]})
Thereconcile()
function accepts several options.
type_id
- The type of items to reconcile against per theAPI specification.top_res
- Either the number of results to return per entry or the string 'all' to return all results.property_mapping
- A list of properties to filter results on per theAPI specification.reconciliation_endpoint
- The reconciliation service to connect to. Defaults tohttps://wikidata.reconci.link/en/api
.
Although my opinion may be biased, I thinkreconciler
is a pretty nice package.But the thing is, it probably won't fulfill all your Wikidata-related needs.Here are other packages that could help with that:
WikidataIntegrator has a lot of very nice, low-level, functionsfor dealing with various wikidata-related activities, such as item acquisition and programmatic editing.
wikidata2df is a very simple utility package for quickly and easilyturning wikidata SPARQL queries into Pandas DataFrames.
About
Python package to reconcile DataFrames