I'm parsing my data from JSON to following DataFrame, but I'm not able to remove the extra stuff from readingtime column & convert it to datetime format
readingtime deviceId
0 {u'$date': u'2014-11-04T17:27:50.000+0000'} 1224EG12
I tried using replace, lstring-rstring but I'm not able to replace the extra characters from thr readingtime column
da2['readingtime2'] = da2['readingtime'].str.replace('date', '')
data['readingtime'] = data['readingtime'].map(lambda x: str(x)[13:])
Tried loc as well but not getting errors
EDITED :
I want final readingtime to be '2014-11-04 17:27:50.000 +000' which I want to convert to datetime - yyyy-mm-dd hh:mm:ss.mils +UTC
You can apply a lambda function to the column of the data frame, extracting the date from the dictionary via
x['$date']
, and then just take the date/time portion (ignoring the time offset). As this is a 'datetime naive' object, Python wouldn't know what to do with any timezone adjustment. Use this stripped date/time string (e.g. '2014-11-04T17:27:50.000') as the input tostrptime
.