Python pandas apply function if a column value is not NULL

后端 未结 4 695
面向向阳花
面向向阳花 2021-02-01 03:00

I have a dataframe (in Python 2.7, pandas 0.15.0):

df=
       A    B               C
0    NaN   11             NaN
1    two  NaN  [\'foo\', \'bar\']
2  three   3         


        
4条回答
  •  一整个雨季
    2021-02-01 03:52

    Try...

    df['a'] = df['a'].apply(lambda x: x.replace(',','\,') if x != None else x)
    

    this example just adds an escape character to a comma if the value is not None

提交回复
热议问题