1
我有一個JSON文件格式如下在python中解析嵌套的JSON?
{
"_id": {
"$oid": "5458c00ceb23024b941be4bb"
},
"gpstime": 0.046575,
"gpslat": 12.94492917,
"readingtime": {
"$date": "2014-11-04T17:28:10.000+0000"
},
"gpslong": 77.56115458,
"deviceid": "11119828",
"time": "Tue Nov 4 12:01:16 2014",
"location": [
12.94492917,
77.56115458
]
}
我用下面的代碼來分析它,但它是直到上日期錯過了
import json
import csv
import pandas as pa
with open('readings.json', 'rb') as f:
data = f.readlines()
data = map(lambda x: x.rstrip(), data)
data_json_str = "[" + ','.join(data) + "]"
data_df = pa.read_json(data_json_str)
我得到readingtime列如下
readingtime {u'$date': u'2014-11-04T17:27:50.000+0000'}
但是在閱讀時錯過了%date
如何解決這個問題?
如何在解析時將時間字段轉換爲日期時間格式?另外如何正確解析閱讀時間字段以獲取日期和時間? – Nishad
http://stackoverflow.com/questions/17134716/convert-dataframe-column-type-from-string-to-datetime – dlask