如何将已解析的json文件转换为pandas数据框? [英] How to convert a parsed json file to pandas data frame?

查看:487
本文介绍了如何将已解析的json文件转换为pandas数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无效行的json文件.我是用这段代码阅读的

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))

很抱歉,代码看起来很丑,我正在使用移动Stack Exchange应用.我想做的是将数据对象转换为数据帧,其中列是每个数据对象列表的前5个元素.你能帮我吗? 干杯!

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!

丹妮

推荐答案

我感到有些as愧.就像使用Dataframe方法一样简单:

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

df = pd.DataFrame(data)

df = pd.DataFrame(data)

这篇关于如何将已解析的json文件转换为pandas数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆