Column contains column 3

前端 未结 1 1643
一生所求
一生所求 2020-12-12 04:50

I have a dataframe. I would like to test whether, (C), on each row, the number in column (B) is in the string, column (A).

df = pd.DataFrame({\'A\': [\"me 12         


        
相关标签:
1条回答
  • 2020-12-12 05:13

    Values NaNs are floats, so you can convert output to floats:

    df['C'] = df.A.str.extract('(\d+)', expand=False).astype(float).eq(df.B,0).astype(int)
    
    0 讨论(0)
提交回复
热议问题