Search code examples
pythonpandasdataframe

Replacing values containing specific character in a Dataframe


I have a pandas dataframe, and in some columns there are values such as "<0.5, <10, <100" etc. I want to replace all those values with 0 if the value just contains "<". How can I do it? I'm relatively new with Python.

Tried to use pd.DataFrame.replace().


Solution

  • The following statement sets all Values in The Column "Column" that contain "<" to 0.

    na=False makes sure that no empty rows are affected by this operation.

    df[df["Column"].str.contains("<",na=False)]=0