A certain dataframe, has a similar break with the one below:
import pandas as pd
df = pd.DataFrame({'name': ['John', 'Elvis', 'Gerrard', 'Pitty'],
'age': [22,23,24,25],
'document': [111,222,333,4444]})
How can I make a filter to return only the rows where the values in the document column are only 3 digits?
log
df.query('2 <= log10(document) < 3')
name age document
0 John 22 111
1 Elvis 23 222
2 Gerrard 24 333
df = pd.DataFrame({
'name': ['John', 'Elvis', 'Gerrard', 'Pitty'],
'age': [22, 23, 24, 25],
'document': [11, 222, 999, 1000]
})
df
name age document
0 John 22 11 # 2 digit number
1 Elvis 23 222 # 3 digit number
2 Gerrard 24 999 # 3 digit number | edge case
3 Pitty 25 1000 # 4 digit number | edge case
Let's get only 3 digit numbers
df.query('2 <= log10(document) < 3')
name age document
1 Elvis 23 222
2 Gerrard 24 999
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With