Add names to dataframe - #235
Merged
jm-rivera merged 6 commits intoApr 8, 2025
Merged
Conversation
To `to_observation_records`
- Add `add_entity_names_to_observations_dataframe` which inserts resolved names for specific columns in a dataframe - Add `flatten_names_dictionary` which converts a dictionary of `Name` objects into a flat dcid->name dict. - Modifies `.to_observation_records` in order to insert names for `entity` and `variable` for a more userfriendly DataFrame
Merged
dwnoble
approved these changes
Apr 8, 2025
Contributor
|
Hey all,
Maybe it's my stupid environment again, but after git cloning on a new
path, I'm getting this error:
>> import datacommons_client
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/google/home/kmoscoe/newpython/api-python/datacommons_client/__init__.py",
line 8, in <module>
from datacommons_client.client import DataCommonsClient
File
"/usr/local/google/home/kmoscoe/newpython/api-python/datacommons_client/client.py",
line 8, in <module>
from datacommons_client.utils.dataframes import
add_entity_names_to_observations_dataframe
File
"/usr/local/google/home/kmoscoe/newpython/api-python/datacommons_client/utils/dataframes.py",
line 15, in <module>
observations_df: pd.DataFrame,
^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'DataFrame'
Any ideas?
…On Tue, Apr 8, 2025 at 1:05 PM Jorge Rivera ***@***.***> wrote:
Merged #235 <#235> into
master.
—
Reply to this email directly, view it on GitHub
<#235 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BHMM7UGCLCDHUGKOCOIDTG32YQTXRAVCNFSM6AAAAAB2WW2LVSVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJXGE3TOMRUGQ2DCNA>
.
You are receiving this because you were mentioned.Message ID:
<datacommonsorg/api-python/pull/235/issue_event/17177244414
***@***.***>
|
Contributor
|
(FYI, I installed hatch, ran hatch env create, ran hatch build and still
the same error.)
…On Tue, Apr 8, 2025 at 4:03 PM Kara Moscoe ***@***.***> wrote:
Hey all,
Maybe it's my stupid environment again, but after git cloning on a new
path, I'm getting this error:
>>> import datacommons_client
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/google/home/kmoscoe/newpython/api-python/datacommons_client/__init__.py",
line 8, in <module>
from datacommons_client.client import DataCommonsClient
File
"/usr/local/google/home/kmoscoe/newpython/api-python/datacommons_client/client.py",
line 8, in <module>
from datacommons_client.utils.dataframes import
add_entity_names_to_observations_dataframe
File
"/usr/local/google/home/kmoscoe/newpython/api-python/datacommons_client/utils/dataframes.py",
line 15, in <module>
observations_df: pd.DataFrame,
^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'DataFrame'
Any ideas?
On Tue, Apr 8, 2025 at 1:05 PM Jorge Rivera ***@***.***>
wrote:
> Merged #235 <#235> into
> master.
>
> —
> Reply to this email directly, view it on GitHub
> <#235 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/BHMM7UGCLCDHUGKOCOIDTG32YQTXRAVCNFSM6AAAAAB2WW2LVSVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJXGE3TOMRUGQ2DCNA>
> .
> You are receiving this because you were mentioned.Message ID:
> <datacommonsorg/api-python/pull/235/issue_event/17177244414
> ***@***.***>
>
|
Contributor
|
Never mind, I forgot to run source env/bin/activate. That seems to be the
only way I can run Python on my machine. hatch env create just doesn't work.
…On Tue, Apr 8, 2025 at 4:07 PM Kara Moscoe ***@***.***> wrote:
(FYI, I installed hatch, ran hatch env create, ran hatch build and still
the same error.)
On Tue, Apr 8, 2025 at 4:03 PM Kara Moscoe ***@***.***> wrote:
> Hey all,
>
> Maybe it's my stupid environment again, but after git cloning on a new
> path, I'm getting this error:
>
> >>> import datacommons_client
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File
> "/usr/local/google/home/kmoscoe/newpython/api-python/datacommons_client/__init__.py",
> line 8, in <module>
> from datacommons_client.client import DataCommonsClient
> File
> "/usr/local/google/home/kmoscoe/newpython/api-python/datacommons_client/client.py",
> line 8, in <module>
> from datacommons_client.utils.dataframes import
> add_entity_names_to_observations_dataframe
> File
> "/usr/local/google/home/kmoscoe/newpython/api-python/datacommons_client/utils/dataframes.py",
> line 15, in <module>
> observations_df: pd.DataFrame,
> ^^^^^^^^^^^^
> AttributeError: 'NoneType' object has no attribute 'DataFrame'
>
> Any ideas?
>
> On Tue, Apr 8, 2025 at 1:05 PM Jorge Rivera ***@***.***>
> wrote:
>
>> Merged #235 <#235>
>> into master.
>>
>> —
>> Reply to this email directly, view it on GitHub
>> <#235 (comment)>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/BHMM7UGCLCDHUGKOCOIDTG32YQTXRAVCNFSM6AAAAAB2WW2LVSVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJXGE3TOMRUGQ2DCNA>
>> .
>> You are receiving this because you were mentioned.Message ID:
>> <datacommonsorg/api-python/pull/235/issue_event/17177244414
>> ***@***.***>
>>
>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This should hopefully be the last 2.0.0 feature - exciting times!
TL:DR: Improve the Observations DataFrame to include
entityandvariablenames.This PR:
add_entity_names_to_observations_dataframewhich inserts resolved names for specific columns in a dataframeflatten_names_dictionarywhich converts a dictionary ofNameobjects into a flat dcid->name dict..observations_dataframein order to insert names forentityandvariablefor a more user-friendly DataFrameFor
Previously
With this PR
@kmoscoe FYI for the docs.