A. Reading excel files, other data sources will encounter some can not be converted or specially marked strings, etc., can not be used directly. At this moment
1.replace()
str.replace(old, new[, max])
- old - substring to be replaced.
- new - new string for replacing old substring.
- max - optional string, alternatively no more than max times
Regular Expressions:
One:
1) or expression can refer to Baidu core programming python pyton base 3 or 3
2) '\' representatives to remove the original meaning of the regular expression characters. For example: \ $ represent him just an average $ characters
1. Query qualified data, search data from left to right through all the data is not found to meet the requirements of qualified data return None, match will be screened from a starting position does not meet the return None
Syntax: search (pattern, string, flags = 0)
- pattern - a searchable format
- string - search for content
- flags - Format
string='{"ss":"${aa}","dd":11}'
pattern='11'
pattern_2='\$\{aa\}'
Invocation:
a=re.search(pattern,string)
pring(a)
2. Get to the results of this inquiry, here only show one way. About groups () will not be discussed.
Syntax: group (self, * args)
Usage: a.groups ()
2. Replace qualified data, can only str type of data to be replaced, the query is the same.
Syntax: sub (pattern, repl, string, count = 0, flags = 0)
- pattern - a searchable format
- repl - the result needs to be replaced
- string - Content
- The number of replacement - count
用法:a=re.search(pattern,string).group()
rp=re.sub(pattern,'123',string,1)
print(rp)