값에서 유추된 유형의 문자열을 반환하려면 index.inferred_type을 사용하세요. Pandas의 속성
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd import numpy as np
인덱스 생성. NaN의 경우 numpy 라이브러리를 사용했습니다 -
index = pd.Index(['Car','Bike', np.nan,'Car',np.nan, 'Ship', None, None])
인덱스 표시 -
print("Pandas Index...\n",index) 값에서 유추된 유형의 문자열을 반환 -
print("\nThe inferred type...\n",index.inferred_type)
예시
다음은 코드입니다 -
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', None, None])
# 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 the dtype of the data
print("\nThe dtype object...\n",index.dtype)
# Return a string of the type inferred from the values
print("\nThe inferred type...\n",index.inferred_type) 출력
이것은 다음 코드를 생성합니다 -
Pandas Index... Index(['Car', 'Bike', nan, 'Car', nan, 'Ship', None, None], dtype='object') Array... ['Car' 'Bike' nan 'Car' nan 'Ship' None None] Is the Pandas index having NaNs? True The dtype object... object The inferred type... Mixed