
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Pandas - Append a collection of Index options together
To append a collection of Index options together, use the append() method in Pandas. At first, import the required libraries −
import pandas as pd
Creating Pandas index −
index1 = pd.Index([10, 20, 30, 40, 50])
Display the Pandas index −
print("Pandas Index...\n",index1)
Create a new index to be appended −
index2 = pd.Index([60, 70, 80])
Append the new index −
print("\nAfter appending...\n",index1.append(index2))
Example
Following is the code −
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))
Output
This will produce the following output −
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')
- Related Articles
- Python – Append List every Nth index
- How to append a list to a Pandas DataFrame using append() in Python?
- Python Pandas - How to append rows to a DataFrame
- Python - Create a new view of the Pandas Index
- Python Pandas - Return a sorted copy of the index
- Python Pandas - Return a list of the Index values
- Python Pandas - Repeat elements of an Index
- HTML DOM Datalist options Collection
- Python Pandas - Alter index name
- Append list of dictionaries to an existing Pandas DataFrame in Python
- Append all elements of another Collection to a Vector in Java
- Python Pandas - Return the Transpose of the index
- Python Pandas - Set the name of the index
- Python Pandas - Create a DataFrame from original index but enforce a new index
- How to append a pandas Series object to another Series in Python?

Advertisements