0

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.

5
  • 2
    What does pd.DataFrame( your_dict['minutes'] ) give you? Commented Aug 30, 2022 at 3:04
  • it gives: "TypeError: list indices must be integers or slices, not str" Commented Aug 30, 2022 at 3:15
  • I did read the other posts with this error code but wasnt able to get past it Commented Aug 30, 2022 at 3:17
  • You may want to write a minimum reproducible example. Without knowing your data fully it is not possible to comment. Commented Aug 30, 2022 at 3:20
  • You should share a better sample, as @SomeDude suggests, that code makes the magic. Commented Aug 30, 2022 at 3:21

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.