In pandas add suffix can be used for both series and dataframe. It is used to suffix labels with string suffix. In series rows, labels are suffixed. In DataFrame columns, labels are suffixed.
Syntax
DataFrame.add_suffix(suffix)
Parameters:
suffix: The string to which we can add after each label.
Returns:
It may be a series or dataframe with updated labels.
Example
import pandas as pd
df_0= pd.DataFrame({'A': [1, 2, 3, 4], 'B': [5, 6, 7, 8]})
df_0
Output
A | B | |
---|---|---|
0 | 1 | 5 |
1 | 2 | 6 |
2 | 3 | 7 |
3 | 4 | 8 |
df_0.add_suffix('_a')
Output
A_a | B_a | |
---|---|---|
0 | 1 | 5 |
1 | 2 | 6 |
2 | 3 | 7 |
3 | 4 | 8 |