python requests 库请求带有文件参数的接口实例
344
2022-08-24
python_字符串处理&正则(Python字符串处理成字典)
python_字符串处理&正则
String ManipulationString Object Methodsval = 'a,b, guido'val.split(',')pieces = [x.strip() for x in val.split(',')]piecesfirst, second, third = piecesfirst + '::' + second + '::' + third'::'.join(pieces)'guido' in valval.index(',')val.find(':')val.index(':')val.count(',')val.replace(',', '::')val.replace(',', '')Regular Expressionsimport retext = "foo bar\t baz \tqux"re.split('\s+', text)regex = re.compile('\s+')regex.split(text)regex.findall(text)text = """Dave dave@google.comSteve steve@gmail.comRob rob@gmail.comRyan ryan@yahoo.com"""pattern = r'[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'# re.IGNORECASE makes the regex case-insensitiveregex = re.compile(pattern, flags=re.IGNORECASE)regex.findall(text)m = regex.search(text)mtext[m.start():m.end()]print(regex.match(text))print(regex.sub('REDACTED', text))pattern = r'([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\.([A-Z]{2,4})'regex = re.compile(pattern, flags=re.IGNORECASE)m = regex.match('wesm@bright.net')m.groups()regex.findall(text)print(regex.sub(r'Username: \1, Domain: \2, Suffix: \3', text))Vectorized String Functions in pandasdata = {'Dave': 'dave@google.com', 'Steve': 'steve@gmail.com', 'Rob': 'rob@gmail.com', 'Wes': np.nan}data = pd.Series(data)datadata.isnull()data.str.contains('gmail')patterndata.str.findall(pattern, flags=re.IGNORECASE)matches = data.str.match(pattern, flags=re.IGNORECASE)matchesmatches.str.get(1)matches.str[0]data.str[:5]pd.options.display.max_rows =
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~