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
  • 8,367
  • 7
  • 44
  • 80
LLL
  • 359
  • 1
  • 3
  • 13

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
  • 131,600
  • 10
  • 43
  • 63