Python
 Computer >> コンピューター >  >> プログラミング >> Python

Python-Pandasインデックスが整数のみで構成されているかどうかを確認します


パンダインデックスが整数のみで構成されているかどうかを確認するには、 index.is_integer()を使用します パンダのメソッド。まず、必要なライブラリをインポートします-

import pandas as pd

パンダインデックスの作成-

index = pd.Index([5, 10, 25, 50, 75, 100, 125, 150])

パンダのインデックスを表示する-

print("Pandas Index...\n",index)

インデックス値にintのみがあるかどうかを確認します-

print("\nIndex values only consists of integers?\n",index.is_integer())

以下はコードです-

import pandas as pd

# Creating Pandas index
index = pd.Index([5, 10, 25, 50, 75, 100, 125, 150])

# 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 ints
print("\nIndex values only consists of integers?\n",index.is_integer())
のみがあるかどうかを確認します

出力

これにより、次の出力が生成されます-

Pandas Index...
Int64Index([5, 10, 25, 50, 75, 100, 125, 150], dtype='int64')

Number of elements in the index...
8

The dtype object...
int64

Index values only consists of integers?
True

  1. Python-PandasIndexがカテゴリデータを保持しているかどうかを確認します

    Pandas Indexがカテゴリデータを保持しているかどうかを確認するには、 index.is_categorical()を使用します パンダのメソッド。まず、必要なライブラリをインポートします- import pandas as pd タイプをカテゴリに設定してPandasインデックスを作成する astype()を使用する メソッド- index = pd.Index(["Electronics","Accessories","Furniture"]).astype("category") パンダのイン

  2. 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("\nInde