- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a Python code to concatenate two Pandas series into a single series without repeating the index
Input − Assume, you have a series and the result to concat the values without repeating the index is,
0 1 1 2 2 3 3 4 4 5 5 6
Solution
To solve this, we will follow these two steps −
Define two Series
Concat two series and apply ignore_index value as True to find the result. It is defined below,
pd.concat([series_one,series_two],ignore_index=True)
Example
Let us see the complete implementation to get a better understanding −
import pandas as pd series_one = pd.Series([1,2,3]) series_two = pd.Series([4,5,6]) print(pd.concat([series_one,series_two],ignore_index=True))
Output
0 1 1 2 2 3 3 4 4 5 5 6
Advertisements