蟒蛇|熊猫。CategoricalDtype()

熊猫。应用程序编程接口。类型。CategoricalDtype(categories=None,ordered=None): 此类用于指定独立于值的类别数据类型,并具有类别和顺序。

null

Parameters- 类别: [索引式]类别的独特分类。 命令: [boolean]如果为false,则该范畴被视为无序。

Return- 分类数据的类型规范

代码:

# Python code explaining
# numpy.pandas.CategoricalDtype()
# importing libraries
import numpy as np
import pandas as pd
from pandas.api.types import CategoricalDtype
a = CategoricalDtype([ 'a' , 'b' , 'c' ], ordered = True )
print ( "a : " , a)
b = CategoricalDtype([ 'a' , 'b' , 'c' ])
print ( "b : " , b)
print ( "True / False : " , a = = CategoricalDtype([ 'a' , 'b' , 'c' ],
ordered = False ))
c = pd.api.types.CategoricalDtype(categories = [ "a" , "b" , "d" , "c" ], ordered = True )
print ( "Type : " , c)


图片[1]-蟒蛇|熊猫。CategoricalDtype()-yiteyi-C++库

c1 = pd.Series([ 'a' , 'b' , 'a' , 'e' ], dtype = c)
print ( "c1 : " , c1)
c2 = pd.DataFrame({ 'A' : list ( 'abca' ), 'B' : list ( 'bccd' )})
c3 = CategoricalDtype(categories = list ( 'abcd' ), ordered = True )
c4 = c2.astype(c3)
print ( " c4['A'] : " , c4[ 'A' ])


图片[2]-蟒蛇|熊猫。CategoricalDtype()-yiteyi-C++库

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享