1

I have a JSON file in following format

{
  "_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
  ]
}                                                                                                         

I used the following code to parse it but it is till missing out on date

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)  

I get readingtime column as follows

readingtime  {u'$date': u'2014-11-04T17:27:50.000+0000'}                                                                 

But is missing out on %date in reading time how to fix this ?

TaoPR
  • 5,932
  • 3
  • 25
  • 35
wololo
  • 345
  • 2
  • 12

1 Answers1

0

The time field is correctly read, it correctly obtains its own column:

>>> print data_df.time
0    Tue Nov  4 12:01:16 2014
Name: time, dtype: object

Please note that neither $date nor time fields are intepreted, they are just loaded as strings.

dlask
  • 8,776
  • 1
  • 26
  • 30
  • 1
    how to convert time field to datetime format while parsing? Also How to parse the readingtime field properly to get date&time? – wololo Jun 20 '15 at 18:55
  • http://stackoverflow.com/questions/17134716/convert-dataframe-column-type-from-string-to-datetime – dlask Jun 20 '15 at 18:57