인덱스에 NaN이 있는지 확인하려면 index.hasnans를 사용하세요. Pandas의 속성
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd import numpy as np
인덱스 생성. NaN의 경우 numpy 라이브러리를 사용했습니다 -
index = pd.Index(['Car','Bike', np.nan,'Car',np.nan, 'Ship'])
인덱스 표시 -
print("Pandas Index...\n",index) 인덱스에 NaN이 있는지 확인 -
print("\nIs the Pandas index having NaNs?\n",index.hasnans)
예시
다음은 코드입니다 -
import pandas as pd
import numpy as np
# Creating the index
# For NaN, we have used numpy library
index = pd.Index(['Car','Bike', np.nan,'Car',np.nan, 'Ship'])
# Display the index
print("Pandas Index...\n",index)
# Return an array representing the data in the Index
print("\nArray...\n",index.values)
# Check if the index is having NaNs
print("\nIs the Pandas index having NaNs?\n",index.hasnans)
# Return a tuple of the shape of the underlying data
print("\nA tuple of the shape of underlying data...\n",index.shape) 출력
이것은 다음 코드를 생성합니다 -
Pandas Index... Index(['Car', 'Bike', nan, 'Car', nan, 'Ship'], dtype='object') Array... ['Car' 'Bike' nan 'Car' nan 'Ship'] Is the Pandas index having NaNs? True A tuple of the shape of underlying data... (6,)