0

I am trying to create a subset of data based on conditions of a certain column in the original data set. It works fine with only one condition (For example, data[TNT]<10000, but it doesn't work if I want to limit it within a range (data[TNT]>10000 and data[TNT]<25000.

#group2= 10k<TNT<25k
group2_b =  data['TNT']>10000 and data['TNT']<=25000
group2 = data[group2_b]

The error message is:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
finefoot
  • 9,914
  • 7
  • 59
  • 102
LLL
  • 419
  • 2
  • 6
  • 17

1 Answers1

-1

Try to add parentheses:

group2_b = (data['TNT']>10000) and (data['TNT']<=25000)

Or use method:

group2_b = data['TNT'].gt(10000) & data['TNT'].le(25000)

or use between:

group2_b = data['TNT'].between(10000,25000)
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74