0

I have a given .json file which was saved as a list format (I guess it not proper json format)

as following:

users.json:

[ "user1", "user2" ]

I would like to read it into a pandas data frame and I tried using different types of arguments in the orient argument as following:

import pandas as pd
nodes = pd.read_json('users.json', orient='split')

I would like the results to look like this:

desired_df = pd.DataFrame({'col1': ["user1", "user2"]})

The closest so question I found was

this one

Any help on that would be great! thanks in advance

3
  • what does each json node look like? you'll need to provide that at the least. Commented Oct 27, 2020 at 11:30
  • that's the format of the file I need to read :( if it's not possible to load it somehow, ill take it as an answer Commented Oct 27, 2020 at 11:32
  • You can change column names later df.columns = ['col1'] Commented Oct 27, 2020 at 12:05

1 Answer 1

2

The code below will create the df for you.

BTW - the json file is a valid json

import pandas as pd
import json
with open('users.json') as f:
  data = json.load(f)
desired_df = pd.DataFrame({'col1':data})
print(desired_df)

output

    col1
0  user1
1  user2
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.