
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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')
Advertisements