Pandas Index의 새 보기를 만들려면 index.view() 메서드를 사용하세요. 먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
판다 인덱스 생성 -
index = pd.Index([50, 10, 70, 110, 90, 50, 110, 90, 30])
판다 인덱스 표시 -
print("Pandas Index...\n",index) 새 보기 만들기 -
res = index.view('uint8')
새 보기 표시 -
print("\nThe new view...\n",res) 동일한 기본 가치를 공유합니다 -
print("\nView for 0th index...\n",res[0])
print("\nView for 1st index...\n",res[1]) 예시
다음은 코드입니다 -
import pandas as pd
# Creating Pandas index
index = pd.Index([50, 10, 70, 110, 90, 50, 110, 90, 30])
# 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)
# Create a new view
res = index.view('uint8')
# displaying the new view
print("\nThe new view...\n",res)
# shares the same underlying values
print("\nView for 0th index...\n",res[0])
print("\nView for 1st index...\n",res[1]) 출력
이것은 다음과 같은 출력을 생성합니다 -
Pandas Index... Int64Index([50, 10, 70, 110, 90, 50, 110, 90, 30], dtype='int64') Number of elements in the index... 9 The dtype object... int64 The new view... [ 50 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 70 0 0 0 0 0 0 0 110 0 0 0 0 0 0 0 90 0 0 0 0 0 0 0 50 0 0 0 0 0 0 0 110 0 0 0 0 0 0 0 90 0 0 0 0 0 0 0 30 0 0 0 0 0 0 0] View for 0th index... 50 View for 1st index... 0