Extract data from string in python -


i have .csv file data constructed [datetime, "(data1, data2)"] in rows , have managed import data python time , temp, problem facing how seperate temp string 2 new_temp columns in float format use plotting later on?

my code far is:

import csv import matplotlib.dates dates  def getcolumn(filename, column):     results = csv.reader(open('logfile.csv'), delimiter = ",")     return [result[column] result in results] time = getcolumn("logfile.csv",0) temp = getcolumn("logfile.csv",1) new_time = dates.datestr2num(time) new_temp = [???] 

when print temp ['(0.0, 0.0)', '(64.4164, 66.2503)', '(63.4768, 65.4108)', '(62.7148, 64.6278)', '(62.0408, 63.9625)', '(61.456, 63.2638)', '(61.0234, 62.837)', '(60.6823, 62.317)',...etc]

if can me in advance.

you may use code:

import re string = "['(0.0, 0.0)', '(64.4164, 66.2503)', '(63.4768, 65.4108)', '(62.7148, 64.6278)', '(62.0408, 63.9625)', '(61.456, 63.2638)', '(61.0234, 62.837)', '(60.6823, 62.317)']" data = re.findall('[+-]?\d+\.\d+e?[+-]?\d*', string) data = zip(data[0::2], data[1::2]) print [float(d[0]) d in data] print [float(d[1]) d in data] 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -