Jum*_*dan 1 python regex string replace pandas
我有一列包含 5 个数字,然后是破折号,然后是另外 5 个数字,例如 44004-23323。我想删除中间的破折号。我希望输出类似于 44004023323 我已经尝试了下面的代码,但它不起作用。
df['Lane'] = df['Lane'].apply(lambda x: "0" if x == "-" else x)
Run Code Online (Sandbox Code Playgroud)
小智 5
.str.replace() 怎么样?
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.replace.html
# see documentation for other parameters, such as regex and case
df['Lane'] = df['Lane'].str.replace('-', '0')
Run Code Online (Sandbox Code Playgroud)