filter dataframe rows based on length of column values

后端 未结 4 1312
误落风尘
误落风尘 2021-01-17 18:28

I have a pandas dataframe as follows:

df = pd.DataFrame([ [1,2], [np.NaN,1], [\'test string1\', 5]], columns=[\'A\',\'B\'] )

df
              A  B
0                 


        
4条回答
  •  半阙折子戏
    2021-01-17 19:31

    Use the apply function of series, in order to keep them:

    df = df[df['A'].apply(lambda x: len(x) <= 10)]

提交回复
热议问题