Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。
 Pandas  Index.is_categorical()函數檢查索引是否包含分類數據。分類變量表示可以分為幾組的數據類型。類別變量的示例是種族,性別,年齡組和教育程度。
用法: Index.is_categorical()
參數:不帶任何參數。
返回:如果索引是分類的,則為True。
範例1:采用Index.is_categorical()函數檢查輸入的索引是否是分類的。
# importing pandas as pd 
import pandas as pd 
  
# Creating the categorical Index 
idx = pd.Index(['Labrador', 'Beagle', 'Mastiff', 'Lhasa', 
                    'Husky', 'Beagle']).astype('category') 
  
# Print the Index 
idx輸出:

現在我們發現idx標簽是否是分類的。
# Find whether idx1 is categorical or not. 
idx.is_categorical()輸出:

該函數已返回true,指示索引中包含的值是類別的。
範例2:采用Index.is_categorical()函數來查找索引中包含的值是否是分類的。
# importing pandas as pd 
import pandas as pd 
  
# Creating the Index 
idx = pd.Index(['2015-10-31', '2015-12-02', None, '2016-01-03', 
                      '2016-02-08', '2017-05-05', '2014-02-11']) 
  
# Print the Index 
idx輸出:

現在,我們檢查idx中的標簽是否是分類的。
# test whether idx is having categorical values. 
idx.is_categorical()輸出:

正如我們在輸出中看到的,該函數已返回False指示值在idx索引中不是分類的。
相關用法
- Python pandas.map()用法及代碼示例
 - Python Pandas Series.str.len()用法及代碼示例
 - Python Pandas.factorize()用法及代碼示例
 - Python Pandas TimedeltaIndex.name用法及代碼示例
 - Python Pandas dataframe.ne()用法及代碼示例
 - Python Pandas Series.between()用法及代碼示例
 - Python Pandas DataFrame.where()用法及代碼示例
 - Python Pandas Series.add()用法及代碼示例
 - Python Pandas.pivot_table()用法及代碼示例
 - Python Pandas Series.mod()用法及代碼示例
 - Python Pandas Dataframe.at[ ]用法及代碼示例
 - Python Pandas Dataframe.iat[ ]用法及代碼示例
 - Python Pandas.pivot()用法及代碼示例
 - Python Pandas dataframe.mul()用法及代碼示例
 - Python Pandas.melt()用法及代碼示例
 
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Index.is_categorical()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
