replace string in pandas dataframe

后端 未结 3 1872
南方客
南方客 2020-12-21 06:02

I have a dataframe with multiple columns. I want to look at one column and if any of the strings in the column contain @, I want to replace them with another string. How wou

3条回答
  •  误落风尘
    2020-12-21 06:42

    Assuming you called your dataframe df, you can do:

    pd.DataFrame(map(lambda col: map(lambda x: 'anotherString' if '@' in x else x, df[col]), df.columns)).transpose()
    

提交回复
热议问题