Finding the type of JSON data
Sometimes, you may be tasked to work with a semi-structured dataset with little documentation. When this is the case, you may have to do a certain amount of discovery around data schema and types. To help with this, Postgres offers the json_typeof function, which you'll explore more of in this exercise.
A connection to the disneyland database has been created and is available in the db_engine variable. pandas has been imported as pd, and is ready to use. Happy querying!
Deze oefening maakt deel uit van de cursus
Introduction to NoSQL
Oefeninstructies
- Extract the type of the
locationfield from thereviewcolumn in thenested_reviewstable, aliasing the result aslocation_type. - Execute the query using
pandas, and print the result set.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Find the data type of the location field
query = """
SELECT
____(____ -> '____') AS ____
FROM nested_reviews;
"""
# Execute the query, render results
data = pd.____(____, db_engine)
print(data)