0

I have a dataset where one columns' integer attributes range from 1 to 99999999.

Using pandas, how do I filter that column to only show the specific columns' attributes between 90000000 and 99999999?

Thank you,

  • 2
    What have you tried / researched already? Additionally, the values in the question and title are different. Please clarify the requirement. – S3DEV Aug 12 '21 at 20:12
  • `df[90000000 <= df['columnname'] <= 99999999]` – Barmar Aug 12 '21 at 20:14
  • 2
    @Barmar. While it works very well for python variables, this notation doesn't work with Series. – Corralien Aug 12 '21 at 20:22

2 Answers2

2

Use between:

>>> df = pd.DataFrame({'A': np.random.randint(1, 99999999, 10000)}

>>> df[df['A'].between(90000000, 99999999)]
             A
14    90515447
39    98481777
41    96353791
45    99931205
57    90553633
...        ...
9919  96258260
9926  96892543
9943  99069133
9957  97374508
9980  90698303

[1047 rows x 1 columns]
Corralien
  • 109,409
  • 8
  • 28
  • 52
0
from random import randint

data = [
    [1, randint(1, 10)],
    [2, randint(2, 10)],
    [3, randint(90000000,99999999)],
    [4, randint(4, 10)],
    [5, randint(90000000,99999999)]
]
df = pd.DataFrame(data, columns=['1', '2'])
filtered = df[(df.loc[:, '2'] >= 90000000) & (df.loc[:, '2'] <= 99999999)]
print(filtered)
>> 
    1   2
2   3   91196774
4   5   91362223
chatax
  • 990
  • 3
  • 17