4

Suppose I have given datasets:

Sr.No|Query
-----
 1.   a
 2.   a
 3.   b
 4.   b
 5.   a

I want the following result :

Sr.No | Query | Frequency
1.    a         3
2.    a         3
3.    b         2
4.    b         2
5.    a         3

Please note that the duplicates should not be removed.

1
  • Can you explain how you arrive at the frequency here? also please edit your question so it looks presentable Commented Aug 3, 2016 at 11:12

1 Answer 1

1

You can use transform with size:

df['Frequency']= df.groupby('Query')['Query'].transform('size')
print (df)
   Sr.No Query  Frequency
0    1.0     a          3
1    2.0     a          3
2    3.0     b          2
3    4.0     b          2
4    5.0     a          3
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.