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

When working with Pandas Series, you often need to combine two series into one. By default, concatenating series preserves original indices, which can create duplicates. Using ignore_index=True creates a new sequential index starting from 0.

Syntax

pd.concat([series1, series2], ignore_index=True)

Creating Two Series

Let's start by creating two sample series with sequential data ?

import pandas as pd

series_one = pd.Series([1, 2, 3])
series_two = pd.Series([4, 5, 6])

print("Series One:")
print(series_one)
print("\nSeries Two:")
print(series_two)
Series One:
0    1
1    2
2    3
dtype: int64

Series Two:
0    4
1    5
2    6
dtype: int64

Concatenating with ignore_index=True

Use pd.concat() with ignore_index=True to create a continuous index ?

import pandas as pd

series_one = pd.Series([1, 2, 3])
series_two = pd.Series([4, 5, 6])

result = pd.concat([series_one, series_two], ignore_index=True)
print(result)
0    1
1    2
2    3
3    4
4    5
5    6
dtype: int64

Comparison: With vs Without ignore_index

See the difference between default concatenation and using ignore_index=True ?

import pandas as pd

series_one = pd.Series([1, 2, 3])
series_two = pd.Series([4, 5, 6])

# Default concatenation (preserves original indices)
default_concat = pd.concat([series_one, series_two])
print("Default concatenation:")
print(default_concat)

# With ignore_index=True
reset_concat = pd.concat([series_one, series_two], ignore_index=True)
print("\nWith ignore_index=True:")
print(reset_concat)
Default concatenation:
0    1
1    2
2    3
0    4
1    5
2    6
dtype: int64

With ignore_index=True:
0    1
1    2
2    3
3    4
4    5
5    6
dtype: int64

Working with Different Index Values

This approach is especially useful when series have different index ranges ?

import pandas as pd

# Series with custom indices
series_a = pd.Series([10, 20, 30], index=[1, 3, 5])
series_b = pd.Series([40, 50], index=[2, 4])

result = pd.concat([series_a, series_b], ignore_index=True)
print("Original indices ignored, new sequential index:")
print(result)
Original indices ignored, new sequential index:
0    10
1    20
2    30
3    40
4    50
dtype: int64

Conclusion

Use pd.concat() with ignore_index=True to merge two series with a continuous index. This prevents duplicate indices and creates a clean, sequential result series.

Updated on: 2026-03-25T15:52:34+05:30

427 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements