Pandas Python Regex : error: nothing to repeat

前端 未结 3 400
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 01:10

I have a dataframe with a couple of strange characters, \"*\" and \"-\".

import pandas as pd
import numpy as np

data = {\'year\': [2010, 2011, 2012, 2011,          


        
3条回答
  •  清酒与你
    2021-01-14 01:22

    Do

    football.replace(['*','-'], ['0.00','0.00'], regex=False)
    

    That is, there is no need to use regular expression for a simple case of matching just 1 character or another;

    or if you want to use regular expression, do note that * is a special character; if you want to match values that are '*' or '-' exactly, use

    football.replace('^[*-]$', '0.00', regex=True)
    

提交回复
热议问题