简体   繁体   中英

How can I count how many diverse item in the column 'item'?

How can I count how many diverse items in the column 'item'?

               item
index
0              lm792
1       sotl085-pu01
2              lm792
3       sotl085-pu01
4          ym11-3527
            ...     
9991        Hang tag
9992        Hang tag
9993        Hang tag
9994          Thread
9995          Thread

Try:

df.item.value_counts()

(Assuming your dataframe is named df ).

Assuming your dataframe name is df, you could do

print(len(pd.unique(df.item)))
print(len(df.item.unique()))

Basically you create a list of unqiue items and then get the length of list. Documentation is here https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.unique.html and https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.unique.html#pandas.Series.unique

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM