Để nối một tập hợp các tùy chọn Chỉ mục lại với nhau, hãy sử dụng append () trong Pandas. Đầu tiên, hãy nhập các thư viện được yêu cầu -
import pandas as pd
Tạo chỉ mục Pandas -
index1 = pd.Index([10, 20, 30, 40, 50])
Hiển thị chỉ mục Gấu trúc -
print("Pandas Index...\n",index1) Tạo một chỉ mục mới để thêm vào -
index2 = pd.Index([60, 70, 80])
Nối chỉ mục mới -
print("\nAfter appending...\n",index1.append(index2)) Ví dụ
Sau đây là mã -
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)) Đầu ra
Điều này sẽ tạo ra kết quả sau -
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')