2024-04-25 01:49:01 发布
网友
我有一个列,有5个数字,然后是破折号,然后是另外5个数字,例如44004-23323。我想删除中间的短跑。我希望输出是这样的44004023323 我已经尝试了下面的代码,但它不工作。你知道吗
df['Lane'] = df['Lane'].apply(lambda x: "0" if x == "-" else x)
试试这个
df['Lane'] = df['Lane'].apply(lambda x: str(x).replace('-','0'))
怎么样。结构更换()? 你知道吗
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.replace.html
Pandas: replace substring in string
# see documentation for other parameters, such as regex and case df['Lane'] = df['Lane'].str.replace('-', '0')
试试这个
怎么样。结构更换()? 你知道吗
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.replace.html
Pandas: replace substring in string
相关问题 更多 >
编程相关推荐