[Solved] How to remove part of a data string? [closed]


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

1

solved How to remove part of a data string? [closed]