replace string in pandas dataframe

后端 未结 3 1874
南方客
南方客 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:57

    My suggestion:

    df['col'] = ['new string' if '@' in x else x for x in df['col']]
    

    not sure which is faster.

提交回复
热议问题