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

Updated on: 24-Feb-2021

319 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements