Python Pandas - 將一系列索引選項附加在一起
要將一系列索引選項追加在一起,請使用 Pandas 中的 append() 方法。首先,匯入所需的庫 −
import pandas as pd
建立 Pandas 索引 −
index1 = pd.Index([10, 20, 30, 40, 50])
顯示 Pandas 索引 −
print("Pandas Index...\n",index1)建立一個新索引進行追加 −
index2 = pd.Index([60, 70, 80])
追加新索引 −
print("\nAfter appending...\n",index1.append(index2))示例
以下為程式碼 −
import pandas as pd
# Creating Pandas index
index1 = pd.Index([10, 20, 30, 40, 50])
# Display the Pandas index
print("Pandas Index...\n",index1)
# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index1.size)
# create a new index to be appended
index2 = pd.Index([60, 70, 80])
# Append the new index
print("\nAfter appending...\n",index1.append(index2))輸出
這將產生以下輸出 −
Pandas Index... Int64Index([10, 20, 30, 40, 50], dtype='int64') Number of elements in the index... 5 After appending... Int64Index([10, 20, 30, 40, 50, 60, 70, 80], dtype='int64')
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP