Python ValueError:在panda中使用参数行读取json时需要对象或值=True
我正在处理一个大的有效JSON文件。我正在尝试使用Pandas解析此文件。当我尝试用普通的Python ValueError:在panda中使用参数行读取json时需要对象或值=True,python,json,pandas,Python,Json,Pandas,我正在处理一个大的有效JSON文件。我正在尝试使用Pandas解析此文件。当我尝试用普通的data=pd.read\u json(filename)方法读取此文件时。它读取文件。但是当我尝试使用参数lines=Truedata=pd.read_json(filename,lines=True)its抛出一个错误ValueError:Expected object或value 我想使用块读取此文件。但是如果我使用参数chunksize,我会得到同样的错误 有人能指出我做错了什么吗 filename
data=pd.read\u json(filename)
方法读取此文件时。它读取文件。但是当我尝试使用参数lines=Truedata=pd.read_json(filename,lines=True)
its抛出一个错误ValueError:Expected object或value
我想使用块读取此文件。但是如果我使用参数chunksize,我会得到同样的错误
有人能指出我做错了什么吗
filename='data/tinyTwitter.json'
data = pd.read_json(filename, lines=True, chunksize=100)
资料
{
“总行数”:387777,
“偏移量”:805584,
“行”:[
{
“id”:“570379215192727552”,
“关键”:[
“r1r01cdn8nb4”,
2015,
2.
25
],
“价值”:{
“类型”:“功能”,
“几何学”:{
“类型”:“点”,
“坐标”:[
144.92340088,
-37.95935781
]
},
“财产”:{
“创建时间”:“Wed Feb 25 00:26:16+0000 2015”,
“文本”:“在奥斯卡颁奖典礼上,Lady Gaga每天与声乐教练一起训练6个月,httmelbourne htto/ZSu8FifNUK”,
“地点”:“墨尔本”
}
},
“文件”:{
“_id”:“570379215192727552”,
“修订版”:“1-fa6a485cb4fe0575781b6c29286af554”,
“贡献者”:空,
“截断”:false,
“文本”:“在奥斯卡颁奖典礼上,Lady Gaga每天与声乐教练一起训练6个月,htDIIS5EtsW9#墨尔本ho/ZSu8FifNUK”,
“在对状态id的回复中”:null,
“收藏夹计数”:0,
“来源”:“,
“转发”:错误,
“坐标”:{
“类型”:“点”,
“坐标”:[
144.92340088,
-37.95935781
]
},
“实体”:{
“符号”:[
],
“用户_提到”:[
],
“hashtags”:[
{
“指数”:[
95,
105
],
“文本”:“墨尔本”
}
],
“URL”:[
{
“url”:“,
“指数”:[
72,
94
],
“扩展url”:“,
“显示url”:“j.mp/1ag2Quk”
}
],
“媒体”:[
{
“扩展url”:“,
“显示url”:“pir.FifNUK”,
“url”:“http/ZSu8FifNUK”,
“媒体url\U https”:“,
“id_街”:“57037921542457344”,
“尺寸”:{
“大”:{
“h”:380,
“调整大小”:“适合”,
“w”:380
},
“小”:{
“h”:340,
“调整大小”:“适合”,
“w”:340
},
“中等”:{
“h”:380,
“调整大小”:“适合”,
“w”:380
},
“拇指”:{
“h”:150,
“调整大小”:“裁剪”,
“w”:150
}
},
“指数”:[
106,
128
],
“类型”:“照片”,
“id”:57037915142457340,
“媒体url”:”
}
]
},
“回复至屏幕名称”为空,
“in_reply_to_user_id”:null,
“转发计数”:0,
“id_街”:“570379215192727552”,
“偏爱”:错误,
“用户”:{
“跟踪请求发送”:false,
“profile\u use\u background\u image”:真,
“配置文件\文本\颜色”:“333333”,
“默认_配置文件_图像”:false,
“id”:2543131938,
“配置文件\u背景\u图像\u url\u https”:“”,
“已验证”:错误,
“配置文件位置”:空,
“profile\u image\u url\u https:”,
“配置文件\侧边栏\填充\颜色”:“DDEEF6”,
“实体”:{
“url”:{
“URL”:[
{
“url”:“,
“指数”:[
0,
22
],
“扩展url”:“,
“显示url:“youthnews.com.au”
}
]
},
“说明”:{
“URL”:[
]
}
},
“粉丝数”:68313,
“配置文件\侧边栏\边框\颜色”:“C0”,
“id_街”:“2543131938”,
“配置文件\背景\颜色”:“C0”,
“列出的数量”:6,
“是否已启用翻译”:false,
“utc_偏移量”:36000,
“状态计数”:1390,
“说明”:“媒体网络”,
“朋友数”:788,
“地点”:“太平洋、大洋洲”,
“配置文件链接颜色”:“042A38”,
“配置文件\u图像\u url”:“”,
"跟随":假,,
“geo_enabled”:正确,
“个人资料条幅url”:“h8”,
“配置文件\背景\图像\ url”:“htng”,
“名称”:“ynnmedia”™",
{
"total_rows":3877777,
"offset":805584,
"rows":[
{
"id":"570379215192727552",
"key":[
"r1r01cdn8nb4",
2015,
2,
25
],
"value":{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
144.92340088,
-37.95935781
]
},
"properties":{
"created_at":"Wed Feb 25 00:26:16 +0000 2015",
"text":"For the Oscars, Lady Gaga trained with a vocal coach DAILY for 6 months httmelbourne htto/ZSu8FifNUK",
"location":"melbourne"
}
},
"doc":{
"_id":"570379215192727552",
"_rev":"1-fa6a485cb4fe0575781b6c29286af554",
"contributors":null,
"truncated":false,
"text":"For the Oscars, Lady Gaga trained with a vocal coach DAILY for 6 months htDIIS5EtsW9 #melbourne ho/ZSu8FifNUK",
"in_reply_to_status_id":null,
"favorite_count":0,
"source":"",
"retweeted":false,
"coordinates":{
"type":"Point",
"coordinates":[
144.92340088,
-37.95935781
]
},
"entities":{
"symbols":[
],
"user_mentions":[
],
"hashtags":[
{
"indices":[
95,
105
],
"text":"melbourne"
}
],
"urls":[
{
"url":"",
"indices":[
72,
94
],
"expanded_url":"",
"display_url":"j.mp/1ag2Quk"
}
],
"media":[
{
"expanded_url":"",
"display_url":"pir.FifNUK",
"url":"http/ZSu8FifNUK",
"media_url_https":"",
"id_str":"570379215142457344",
"sizes":{
"large":{
"h":380,
"resize":"fit",
"w":380
},
"small":{
"h":340,
"resize":"fit",
"w":340
},
"medium":{
"h":380,
"resize":"fit",
"w":380
},
"thumb":{
"h":150,
"resize":"crop",
"w":150
}
},
"indices":[
106,
128
],
"type":"photo",
"id":570379215142457340,
"media_url":""
}
]
},
"in_reply_to_screen_name":null,
"in_reply_to_user_id":null,
"retweet_count":0,
"id_str":"570379215192727552",
"favorited":false,
"user":{
"follow_request_sent":false,
"profile_use_background_image":true,
"profile_text_color":"333333",
"default_profile_image":false,
"id":2543131938,
"profile_background_image_url_https":"",
"verified":false,
"profile_location":null,
"profile_image_url_https":"",
"profile_sidebar_fill_color":"DDEEF6",
"entities":{
"url":{
"urls":[
{
"url":"",
"indices":[
0,
22
],
"expanded_url":"",
"display_url":"youthsnews.com.au"
}
]
},
"description":{
"urls":[
]
}
},
"followers_count":68313,
"profile_sidebar_border_color":"C0DEED",
"id_str":"2543131938",
"profile_background_color":"C0DEED",
"listed_count":6,
"is_translation_enabled":false,
"utc_offset":36000,
"statuses_count":1390,
"description":"media network",
"friends_count":788,
"location":"pacific, oceania",
"profile_link_color":"042A38",
"profile_image_url":"",
"following":false,
"geo_enabled":true,
"profile_banner_url":"h8",
"profile_background_image_url":"htng",
"name":"ynnmedia™",
"lang":"en",
"profile_background_tile":false,
"favourites_count":765,
"screen_name":"ynnmedianetwork",
"notifications":false,
"url":"htxq",
"created_at":"Tue Jun 03 09:27:23 +0000 2014",
"contributors_enabled":false,
"time_zone":"Yakutsk",
"protected":false,
"default_profile":false,
"is_translator":false
},
"geo":{
"type":"Point",
"coordinates":[
-37.95935781,
144.92340088
]
},
"in_reply_to_user_id_str":null,
"possibly_sensitive":false,
"lang":"en",
"created_at":"Wed Feb 25 00:26:16 +0000 2015",
"in_reply_to_status_id_str":null,
"place":null,
"metadata":{
"iso_language_code":"en",
"result_type":"recent"
},
"location":"melbourne"
}
},
{
"id":"570379220146200576",
"key":[
"r1r01cdn8nb4",
2015,
2,
25
],
"value":{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
144.92340088,
-37.95935781
]
},
"properties":{
"created_at":"Wed Feb 25 00:26:17 +0000 2015",
"text":"Abuses in AIB Roast were dubbed: Rakhi Sawant Ka",
"location":"melbourne"
}
},
"doc":{
"_id":"570379220146200576",
"_rev":"1-61252163c64f6f548cab2b8eb4cbd045",
"contributors":null,
"truncated":false,
"text":"Abuses in AIB Roast were dubbed: Rakhi Sawant ourne htco/MbglBYEAKa",
"in_reply_to_status_id":null,
"favorite_count":0,
"source":"t</a>",
"retweeted":false,
"coordinates":{
"type":"Point",
"coordinates":[
144.92340088,
-37.95935781
]
},
"entities":{
"symbols":[
],
"user_mentions":[
],
"hashtags":[
{
"indices":[
69,
79
],
"text":"melbourne"
}
],
"urls":[
{
"url":"htKiAELeMO6",
"indices":[
46,
68
],
"expanded_url":"/1ag2Omb",
"display_url":"j.mp/1ag2Omb"
}
],
"media":[
{
"expanded_url":"h79220146200576/photo/1",
"display_url":"pglBYEAKa",
"url":"rr",
"media_url":"pk4O5UIAAI0l",
"id_str":"570379220049731584",
"sizes":{
"large":{
"h":380,
"resize":"fit",
"w":380
},
"small":{
"h":340,
"resize":"fit",
"w":340
},
"medium":{
"h":380,
"resize":"fit",
"w":380
},
"thumb":{
"h":150,
"resize":"crop",
"w":150
}
},
"indices":[
80,
102
],
"type":"photo",
"id":570379220049731600,
"media_urrl":"htpk4O5UIAAI0l1.jpg"
}
]
},
"in_reply_to_screen_name":null,
"in_reply_to_user_id":null,
"retweet_count":0,
"id_str":"570379220146200576",
"favorited":false,
"user":{
"follow_request_sent":false,
"profile_use_background_image":true,
"profile_text_color":"333333",
"default_profile_image":false,
"id":2543131938,
"profile_background_image_url_https":"h/images/themes/theme1/bg.png",
"verified":false,
"profile_location":null,
"profile_image_url_https":"htt/567602629937606657/ZCcCDFzr_normal.jpeg",
"profile_sidebar_fill_color":"DDEEF6",
"entities":{
"url":{
"urls":[
{
"url":"htAxq",
"indices":[
0,
22
],
"expanded_url":"hws.com.au",
"display_url":"youth.au"
}
]
},
"description":{
"urls":[
]
}
},
"followers_count":68313,
"profile_sidebar_border_color":"C0DEED",
"id_str":"2543131938",
"profile_background_color":"C0DEED",
"listed_count":6,
"is_translation_enabled":false,
"utc_offset":36000,
"statuses_count":1390,
"description":"media network",
"friends_count":788,
"location":"pacific, oceania",
"profile_link_color":"042A38",
"profile_image_url":"htes/567602629937606657/ZCcCDFzr_normal.jpeg",
"following":false,
"geo_enabled":true,
"profile_banner_url":"httpanners/2543131938/1424079798",
"profile_background_image_url":"http/themes/theme1/bg.png",
"name":"ynnmedia™",
"lang":"en",
"profile_background_tile":false,
"favourites_count":765,
"screen_name":"ynnmedianetwork",
"notifications":false,
"url":"httgeAxq",
"created_at":"Tue Jun 03 09:27:23 +0000 2014",
"contributors_enabled":false,
"time_zone":"Yakutsk",
"protected":false,
"default_profile":false,
"is_translator":false
},
"geo":{
"type":"Point",
"coordinates":[
-37.95935781,
144.92340088
]
},
"in_reply_to_user_id_str":null,
"possibly_sensitive":false,
"lang":"en",
"created_at":"Wed Feb 25 00:26:17 +0000 2015",
"in_reply_to_status_id_str":null,
"place":null,
"metadata":{
"iso_language_code":"en",
"result_type":"recent"
},
"location":"melbourne"
}
}
]
}
import json
filename='data/tinyTwitter.json'
data = []
with open(filename) as json_file:
data_str = json_file.read()
data_str = data_str.split('[',1)[-1]
data_str = data_str.rsplit(']',1)[0]
data_str = data_str.split('][')
for jsonStr in data_str:
jsonStr = '[' + jsonStr + ']'
temp_data = json.loads(jsonStr)
for each in temp_data:
data.append(each)