Home > Net >  How to see only 5 high results from the duplicates
How to see only 5 high results from the duplicates

Time:08-01

I have a CSV file with 500 rows and 2 columns, one for numbers and the other for the number of duplicates

I want to see only the top 5 results with the number and also the amount of duplicates of that number ???

thank you

import pandas as pd

df000 = pd.read_csv('list_num.csv')
df2 = df000.groupby(['Num_list']).size().reset_index(name ='Total Duplicated')
df2

# results:

    Num_list    Total Duplicated
0      2            1
1      3            7
2      5            1
3      6            6
4      7            7

CodePudding user response:

You can do

out = df2.sort_values('Total Duplicated',ascending=False).head(5)
  • Related