Write a Python code to concatenate two Pandas series into a single series without repeating the index

PythonPandasServer Side ProgrammingProgramming

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
raja
Published on 10-Feb-2021 17:50:48
Advertisements