Pandas category

Pandas DataFrame can contain category data, and convert  grade the native data into category data:

 

Rename different types with meaningful names and call them  Series.cat.categories.

Series.set_categories The method of reordering categories and adding missing ones returns the new by default Series

 

 

 Sort by the order in which the categories were generated, not by vocabulary:

 

 

When grouping by category (groupby), even if a category is empty, it will display:

 

 

 

Guess you like

Origin www.cnblogs.com/leon-joker/p/12681472.html