简体   繁体   中英

pandas unique values multiple columns different dtypes

Similar to pandas unique values multiple columns I want to count the number of unique values per column. However, as the dtypes differ I get the following error: 在此处输入图片说明

The data frame looks like 在此处输入图片说明 A small[['TARGET', 'title']].apply(pd.Series.describe) gives me the result, but only for the category types and I am unsure how to filter the index for only the last row with the unique values per column

Use apply and np.unique to grab the unique values in each column and take its size :

small[['TARGET','title']].apply(lambda x: np.unique(x).size)

Thanks!

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