![]() I hope this article will help you to save time in converting JSON data into a DataFrame. When dealing with nested JSON, we can use the Pandas built-in json_normalize() function. Pandas read_json() function is a quick and convenient way for converting simple flattened JSON into a Pandas DataFrame. notation to access property from a deeply nested object. Glom is a Python library that allows us to use. from glom import glom df = pd.read_json('data/nested_deep.json') df.apply( lambda row: glom(row, 'grade.math')) 0 60 1 89 2 79 Name: students, dtype: int64 How can we do that more effectively? The answer is using read_json with glom. ![]() What about JSON with a nested list? Let’s see how to convert the following JSON into a DataFrame: ![]() Pandas read_json() works great for flattened JSON like we have in the previous example. Same as reading from a local file, it returns a DataFrame, and columns that are numerical are cast to numeric types by default. Image by author > df.info() RangeIndex: 3 entries, 0 to 2 Data columns (total 5 columns): # Column Non-Null Count Dtype - 0 id 3 non-null object 1 name 3 non-null object 2 math 3 non-null int64 3 physics 3 non-null int64 4 chemistry 3 non-null int64 dtypes: int64(3), object(2) memory usage: 248.0+ bytes ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |