Python-PandasIndexがブール値のみで構成されているかどうかを確認します
パンダインデックスがブール値のみで構成されているかどうかを確認するには、 index.is_boolean()を使用します パンダのメソッド。まず、必要なライブラリをインポートします-
import pandas as pd
パンダインデックスの作成
index = pd.Index([True, True, False, False, True, True, True])
パンダのインデックスを表示する-
print("Pandas Index...\n",index) インデックス値にブール値のみがあるかどうかを確認します-
print("\nIndex values only consists of booleans?\n",index.is_boolean())
例
以下はコードです-
import pandas as pd
# Creating Pandas index
index = pd.Index([True, True, False, False, True, True, True])
# Display the Pandas index
print("Pandas Index...\n",index)
# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index.size)
# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)
# check whether index values has only booleans
print("\nIndex values only consists of booleans?\n",index.is_boolean())のみがあるかどうかを確認します 出力
これにより、次の出力が生成されます-
Pandas Index... Index([True, True, False, False, True, True, True], dtype='object') Number of elements in the index... 7 The dtype object... object Index values only consists of booleans? True
-
Python-PandasIndexがフローティングタイプかどうかを確認します
Pandas Indexがフローティングタイプであるかどうかを確認するには、 index.is_floating()を使用します パンダのメソッド。まず、必要なライブラリをインポートします- import pandas as pd パンダインデックスの作成- index = pd.Index([5.7, 6.8, 10.5, 20.4, 25.6, 30.8, 40.5, 50.2]) パンダのインデックスを表示する- print("Pandas Index...\n",index) インデックス値に浮動小数点数しかないかどうかを確認します- print("
-
Python-PandasIndexがカテゴリデータを保持しているかどうかを確認します
Pandas Indexがカテゴリデータを保持しているかどうかを確認するには、 index.is_categorical()を使用します パンダのメソッド。まず、必要なライブラリをインポートします- import pandas as pd タイプをカテゴリに設定してPandasインデックスを作成する astype()を使用する メソッド- index = pd.Index(["Electronics","Accessories","Furniture"]).astype("category") パンダのイン