简体   繁体   中英

Nested .json to pandas dataframe

I have a json file that I want to convert to a Pandas Dataframe. I have tried the previous solutions but could not get it to work.

Here is a sample from the file:

    {"dateTime": "2022-08-18",
    "minutes": [
      {
        "value": 94.5,
        "minute": "2022-08-18T05:01:00"
      },
      {
        "value": 94.4,
        "minute": "2022-08-18T05:02:00"
      },
   
 

I dont' need the "dateTime" column, and I want to get to:

value   minute
94.5   2022-08-18 05:01:00
94.4   2022-08-18 05:02:00

I am unable to extract the "value" and "minute" to seperate columns. Any help would be appreciated.

I might be off here, as others have stated you haven't given code but can you try:

import json
f = open("your PATH")
js = json.load(f)
df = pd.json_normalize(js, 'minutes', ['dateTime'])

This will signal to pandas that "minutes" has nested values and it will dig into them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM