Pandas Index가 숫자 데이터로만 구성되어 있는지 확인하려면 index.is_numeric()을 사용하세요. 방법. 먼저 필요한 라이브러리를 가져옵니다. -
import pandas as pd import numpy as np
정수, 부동 소수점 및 NaN으로 Pandas 인덱스 만들기
index = pd.Index([5, 10.2, 25, 50, 75.2, 100, np.nan])
팬더 인덱스 표시 -
print("Pandas Index...\n",index) 인덱스 값에 숫자 데이터만 있는지 확인합니다. 숫자 데이터에는 정수, 부동 소수점 및 NaN이 포함됩니다. -
index.is_numeric()
예시
다음은 코드입니다 -
import pandas as pd
import numpy as np
# Creating Pandas index with integer, float and NaNs
index = pd.Index([5, 10.2, 25, 50, 75.2, 100, np.nan])
# 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 numeric data.
# Numeric data includes integer, floats and NaNs
print("\nIndex values only consists of numeric data?\n",index.is_numeric()) 출력
이것은 다음과 같은 출력을 생성합니다 -
Pandas Index... Float64Index([5.0, 10.2, 25.0, 50.0, 75.2, 100.0, nan], dtype='float64') Number of elements in the index... 7 The dtype object... float64 Index values only consists of numeric data? True