Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i remove entire row if a column has more than 10 characters using pandas

Delete entire record if column is more than 10 characters how can i delete that entire record.

My dataframe is

Sl.no     name                 reason
1         sara                 hello 
2          ram                  how are you?
3          raghu                how do you do?
4          sai                   hey !!

Expected Output:

Sl.no     name                 reason
1         sara                 hello 
2          sai                 hey !!

Thanks inadvance.

like image 637
tiru Avatar asked Dec 01 '25 22:12

tiru


1 Answers

I believe need boolean indexing with inverted mask from > to <= and find lengths by Series.str.len:

df = df[df['reason'].str.len() <= 10]
print (df)
   Sl.no  name  reason
0      1  sara   hello
3      4   sai  hey !!
like image 142
jezrael Avatar answered Dec 04 '25 11:12

jezrael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!