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,
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,
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]
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