Python 重新打印列,但更改不';在使用正则表达式时不要坚持
我试图使用regex删除Python 重新打印列,但更改不';在使用正则表达式时不要坚持,python,regex,pandas,Python,Regex,Pandas,我试图使用regex删除$符号、、,并将列转换为浮点数 df[[cols]].replace({'\$': '', ',': ''}, regex=True).astype(float) 当我检查我的工作并查看更改是否持续时,我仍然得到$和, 是否有inplace=True参数或其他什么?您可以这样做 df[col].apply(lambda x: float(x.replace('$', '')) 或 的文档替换为:。是的,有一个inplace参数。需要将其重新分配给df[[cols]]=
$
符号、、
,并将列转换为浮点数
df[[cols]].replace({'\$': '', ',': ''}, regex=True).astype(float)
当我检查我的工作并查看更改是否持续时,我仍然得到$
和,
是否有inplace=True
参数或其他什么?您可以这样做
df[col].apply(lambda x: float(x.replace('$', ''))
或
的文档替换为
:。是的,有一个inplace
参数。需要将其重新分配给df[[cols]]=df[[cols]]。替换({'\$:'',':'',regex=True)。astype(float)
df[col].apply(lambda x: x.replace('$', '')).astype(float)