You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, the multi-parameter function lesson also uses earthly. Similar to #85 it would be ideal to remove the complexity that Earthpy adds and to instead open a .json file in one of our data directories.
We can have them create a small function that:
opens the data as publication JSON,
convert it to pandas df, and
then drops some columns.
The second parameter of the function could be the column names to drop.
import [json](https://docs.python.org/3/library/json.html#module-json)
from [pathlib](https://docs.python.org/3/library/pathlib.html#module-pathlib) import [Path](https://docs.python.org/3/library/pathlib.html#pathlib.Path)
import [pandas](https://pandas.pydata.org/docs/index.html#module-pandas) as pd
def load_clean_json(file_path, columns_to_keep):
"""
Load JSON data from a file. Drop unnecessary columns and normalize
to DataFrame.
Parameters
----------
file_path : Path
Path to the JSON file.
columns_to_keep : list
List of columns to keep in the DataFrame.
Returns
-------
dict
Loaded JSON data.
"""
with file_path.open("r") as json_file:
json_data = [json.load](https://docs.python.org/3/library/json.html#json.load)(json_file)
return [pd.json_normalize](https://pandas.pydata.org/docs/reference/api/pandas.json_normalize.html#pandas.json_normalize)(json_data)
The text was updated successfully, but these errors were encountered:
Right now, the multi-parameter function lesson also uses earthly. Similar to #85 it would be ideal to remove the complexity that Earthpy adds and to instead open a .json file in one of our data directories.
We can have them create a small function that:
The second parameter of the function could be the column names to drop.
An example of this function is here in this lesson.
The text was updated successfully, but these errors were encountered: