Python Pandas - 獲取請求標籤的整數位置
要獲取 Pandas 中請求標籤的整數位置,請使用 **index.get_loc()** 方法。首先,匯入所需的庫 -
import pandas as pd
建立 Pandas 索引物件 -
index = pd.Index(list('pqrstuvwxyz'))
顯示 Pandas 索引 -
print("Pandas Index...\n",index)從給定的索引獲取整數位置 -
print("\nDisplay integer location from given index...\n",index.get_loc('w'))
print("\nDisplay integer location from given index...\n",index.get_loc('z'))示例
以下是程式碼 -
import pandas as pd
# create Pandas index object
index = pd.Index(list('pqrstuvwxyz'))
# 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)
# get integer location from the given index
print("\nDisplay integer location from given index...\n",index.get_loc('w'))
print("\nDisplay integer location from given index...\n",index.get_loc('z'))輸出
這將產生以下輸出 -
Pandas Index... Index(['p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], dtype='object') Number of elements in the index... 11 Display integer location from given index... 7 Display integer location from given index... 10
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP