Issue
My data is in the following format:
[{u'value': 7681, u'time': u'2017-07-12T12:15:54.107488923Z'}, {u'value':
7672, u'time': u'2017-07-12T12:26:01.295268409Z'}]
I need to remove all the u
prefixes from this data. How can I do that using Python 2.7? In fact, I want it to be like:
[{'value': 7681, 'time': '2017-07-12T12:15:54.107488923Z'}, {'value':
7672, 'time': '2017-07-12T12:26:01.295268409Z'}]
Solution
It's unclear what ResultSet
is and its format from your question, however the following example code might be helpful:
import csv
csv_filename = 'result_set.csv'
ResultSet = {"(u'maxbotix_depth', None)": [{u'time': u'2017-07-12T12:15:54.107488923Z',
u'value': 7681},
{u'time': u'2017-07-12T12:26:01.295268409Z',
u'value': 7672}]}
with open(csv_filename, mode='wb') as csv_file:
writer = csv.writer(csv_file)
for obj in ResultSet["(u'maxbotix_depth', None)"]:
time, value = obj[u'time'], obj[u'value']
print('time: {}, value: {}'.format(time, value)) # optional
writer.writerow((time, value))
Printed output:
time: 2017-07-12T12:15:54.107488923Z, value: 7681
time: 2017-07-12T12:26:01.295268409Z, value: 7672
Contents of file created:
2017-07-12T12:15:54.107488923Z,7681
2017-07-12T12:26:01.295268409Z,7672
Answered By - martineau
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.