Dani Valverde
Dani Valverde

Reputation: 409

How to convert a parsed json file to pandas data frame?

I have a json file with non valid lines. I read it using this code

import json
import pandas as pd
data = []
with open('json file ') as f:
   for line in f: 
      data.append(json.loads(line))

Sorry about the ugly looking code, I' m using the mobile Stack Exchange app. What I would like to do is to convert the data object into a data frame which columns are the first 5 elements of each data object list. Can you help? Cheers!

Dani

Upvotes: 1

Views: 3273

Answers (1)

Dani Valverde
Dani Valverde

Reputation: 409

I feel a little bit ashamed. It is as easy as using the Dataframe method:

df = pd.DataFrame(data)

Upvotes: 6

Related Questions