Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python Pandas - 기본 데이터의 dtype 객체를 반환합니다.

<시간/>

기본 데이터의 dtype 개체를 반환하려면 index.dtype을 사용하세요. Pandas의 속성

먼저 필요한 라이브러리를 가져옵니다 -

import pandas as pd

인덱스 생성 -

index = pd.Index(['Car','Bike', 'Shop','Car','Airplace', 'Truck'])

인덱스 표시 -

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

데이터의 dtype 반환 -

print("\nThe dtype object...\n",index.dtype)

예시

다음은 코드입니다 -

import pandas as pd

# Creating the index
index = pd.Index(['Car','Bike', 'Shop','Car','Airplace', 'Truck'])

# Display the index
print("Pandas Index...\n",index)

# Return an array representing the data in the Index
print("\nArray...\n",index.values)

# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)

# 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', 'Shop', 'Car', 'Airplace', 'Truck'], dtype='object')

Array...
['Car' 'Bike' 'Shop' 'Car' 'Airplace' 'Truck']

The dtype object...
object

A tuple of the shape of underlying data...
(6,)