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

Python Pandas - 기본 데이터의 차원 수를 반환합니다.

<시간/>

기본 데이터의 차원 수를 반환하려면 index.ndim을 사용합니다. 재산.

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

import pandas as pd

인덱스 생성 -

index = pd.Index([15, 25, 35, 45, 55])

인덱스 표시 -

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

데이터 차원 가져오기 -

print("\nReturn the dimensions...\n",index.ndim)

예시

다음은 코드입니다 -

import pandas as pd

# Creating the index
index = pd.Index([15, 25, 35, 45, 55])

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

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

# Return a tuple of the shape of the underlying data
print("\nA tuple of the shape of underlying data...\n",index.shape)

# get the bytes in the data
print("\nReturn the bytes...\n",index.nbytes)

# get the dimensions of the data
print("\nReturn the dimensions...\n",index.ndim)

출력

이것은 다음 코드를 생성합니다 -

Pandas Index...
Int64Index([15, 25, 35, 45, 55], dtype='int64')

Array...
[15 25 35 45 55]

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

Return the bytes...
40

Return the dimensions...
1