Home > other >  Python regular matching query data
Python regular matching query data

Time:09-28

I the source of data for:
A='drop - DINIW, the dollar index, 94.51, 94.58, 94.65, 94.47, 0.07, 13:23:39,'
Will drop, change into a raise, behind every number will be changed, constant is [- DINIW, the dollar index,], and finally the time format, I just need to decide whether have such, is mainly used to do an API data warehouse check, I have other data warehousing is wrong, don't know how to implement, what a great god know

CodePudding user response:

There are second from bottom of digital if is in front of the drop is negative, raise is positive

CodePudding user response:


CodePudding user response:

A bit complicated, do not know to have Daniel has a simple way:
 # - * - coding: utf-8 - * - 
The import re
A='drop - DINIW, the dollar index, 94.51, 94.58, 94.65, 94.47, 0.07, 13:23:39,'

Def findS (string, CNT) :
L=a.s plit (', ', CNT)
If len (l) & lt; CNT:
The return - 1
Return len (string) - len (l [1]) - len (', ')

If re. Match (r "(drop | raise) - DINIW, the dollar index, (-? \d+\.? \ d * e? -? \ d *? , -? \d+\.? \ d * e? -? \ d *? , -? \d+\.? \ d * e? -? \ d *? , -? \d+\.? \ d * e? -? \ d *? , -? \d+\.? \ d * e? -? \ d *? , (\ d {1, 2} : \ d {1, 2} : \ d {1, 2}), \ Z ", a) :
The tar=a [0: Anderson ndex (' - DINIW)]
The begin=findS a, (6)
End=findS (a, 7)
Val=a [begin + 1: end]
If the tar=='drop' :
If a float (val) & lt; 0:
Print (a)
The else:
Print (' No match)
Elif tar=='raise:
If a float (val) & gt; 0:
Print (a)
The else:
Print (' No match)
The else:
Print (" No match ")
  • Related