0

I'm trying to aggregate data in a pandas series based on its numeric 3 digit ID (101, 234, 531, 232) and I want to find a way that I can create a series with the count of all of the values in the range of hundreds (100 : 1, 200: 2, 500 : 1). Is there any way to do this using numpy/pandas functions instead of just iterating through the series and counting each value individually?

1 Answer 1

1

The following code should give you the correct output:

df.groupby(df['id']//100*100).count()

Output:

    id  
100 1
200 2
500 1
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.