dimanche 10 juillet 2016

Python regex extracting floatin values

I have data that has strings with floating numbers like

"['0.0'" and '82.00.0' and '82.0n'

and I only want to extract floating points till two/one decimal points like so-

"['0.0'" and '82.00.0' and '82.0n' to 0.0, 82.0, 82.0

The data structure is a big quoted CSV like:

"0.0, 82.00.0,...., 82.0n"

I'm iterating through these to store them to the temp

tempprices.split(',') temp =[] for n in range(l, len(tempprices)-1): temp.append(map(ast.literal_eval,re.findall(r'(?<!S)[+-]?d+.d{1,2}(?!.*d)',tempprices[n])))

where l is some index value.

I want to append these to temp like so [0.0, 82.0, 82.0]

How to achieve that?

Aucun commentaire:

Enregistrer un commentaire