【发布时间】:2019-12-26 21:12:06
【问题描述】:
我在学习 Python 时遇到了以下关于 pandas 的语句:
humans['Education'] = (humans[
'Years of post-secondary education (e.g. BA=4; Ph.D.=10)'] .str.replace(r'.*=','').astype(int))
我知道它会创建额外的列,但不确定 replace(r'.*=','') 功能。
【问题讨论】:
-
r'.*=' 是正则表达式 (RegEx),.匹配任何字符,而星号表示匹配一个或多个前面的标记(点)。最后一个标记 = 匹配一个 '=' 字符。匹配此模式的任何内容都将替换为空字符串
标签: python string replace sklearn-pandas