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,

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

2 Answers 2

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] 
Sign up to request clarification or add additional context in comments.

Comments

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.