I have a dataframe df like:
number | col1
123 | a
1234 | b
567 | c
I want to count how many rows have more or less than 3 digits in column "number". The column as dtype = int64.
When I try:
count = df.query(
"""
... 'some other filters' or \
number.str.len() != 3
"""
)
print(count)
I get:
AttributeError: Can only use .str accessor with string values!
Trying to convert to str() with
count = df.query(
"""
... 'some other filters' or \
str(number).str.len() != 3
"""
)
print(count)
ValueError: "str" is not a supported function
Converting to string would also count negative signs so that's not really a solution anyway.
Removing that check for len = 3 removes all error messages and prints the count.
How can I count the digits in a dataframe query without converting to str and without apply (way too slow for my amount of rows)?