I have a dataframe df
user_id o_date month
2 3 2017-05-15 4
3 3 2017-05-15 4
6 1 2017-05-25 4
22 7 2017-05-27 4
25 1 2017-05-23 4
26 3 2017-05-12 4
29 3 2017-05-13 4
39 7 2017-05-08 4
70 1 2017-05-25 4
I want to sort the 'user_id' to get a new dataframe that resulting object will be in descending order so that the first element is the most frequently-occurring element.Just like the method Series.value_counts()
I want the output
like this:
user_id o_date month
2 3 2017-05-15 4
3 3 2017-05-15 4
26 3 2017-05-12 4
29 3 2017-05-13 4
6 1 2017-05-25 4
25 1 2017-05-23 4
70 1 2017-05-25 4
22 7 2017-05-27 4
39 7 2017-05-08 4
So how to get the output
Thx!
Edit:
I get the output
. Now I want to remove the duplicated user_id
according to the o_date
(with the same user_id
I choose the o_date
which frequently-occurring) just like the final result
:
user_id o_date month
2 3 2017-05-15 4
6 1 2017-05-25 4
22 7 2017-05-27 4
I'm new to the dataframe, thanks again!