filter dataframe rows based on length of column values

后端 未结 4 1297
误落风尘
误落风尘 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:20

    I had to cast to a string for Diego's answer to work:

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

提交回复
热议问题