3
votes

I have a column and i want to find the length which is between 10 and 100 (for ex)

len(data[ 10 < data['TAHSILAT_DEGISIM_DEGER'] <= 100] )

error is : The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

3

3 Answers

4
votes

Use Series.between with sum for count only True values:

data['TAHSILAT_DEGISIM_DEGER'].between(10, 100, inclusive=False).sum()

Or your solution:

len(data[data['TAHSILAT_DEGISIM_DEGER'].between(10, 100, inclusive=False)])
0
votes

use len() with series data type docs of len() function

data[ 10 < data['TAHSILAT_DEGISIM_DEGER'].str.len() <= 100]

or

 data[(data['TAHSILAT_DEGISIM_DEGER'].str.len()) <= 100 & (data['TAHSILAT_DEGISIM_DEGER'].str.len())>10]
0
votes

your error comes from the wrong way to use the filter with multiple conditions, so you could use:

len(data[ (10 < data['TAHSILAT_DEGISIM_DEGER']) & (data['TAHSILAT_DEGISIM_DEGER']<= 100]) )