1

I have a dataframe users which consists of three columns id, username and password.

I am trying to get a count of the rows which have less than 8 numbers of characters in password. My code:

# Calculating the length of user's passwords
users['length'] = users.password.str.len()

# Flagging the users with too short passwords`

users['too_short'] = pd.cut(users['length'], bins=[0,7,300], labels=[True,False])

print (users[users['too_short'].any(1)])

# Counting and printing the number of users with too short passwords
print(users['too_short'].count())

# Taking a look at the 12 first rows
users.head(12)

It gives the following error:

TypeError: Categorical cannot perform the operation any

Column too_short has a value either True or False. I am trying to find a way to count the number of rows in this column based on the boolean values, but with no luck.

1 Answer 1

1

Try this:

users['too_short'] = users['length'] < 7

print(users[users['too_short']])
print(users['too_short'].count())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.