In pandas, the add_suffix()
function adds a suffix to the row labels of a Series object.
The add_suffix()
function takes the syntax shown below:
add_suffix("XYZ")
The add_suffix()
function takes a single required parameter value, suffix
, which represents the string to add as a suffix to the row label of the Series object.
The add_suffix()
function returns a new series with its row labels updated.
Let's consider an example:
# A code to illustrate the add_suffix() function in pandas# Importing the pandas libraryimport pandas as pd# Creating a Series objectmy_series = pd.Series([10, 20, 30, 40, 50])# Printing the Series objectprint(my_series)# Adding a suffix to the row labelsprint(my_series.add_suffix("_row"))
pandas
library.my_series
.my_series
."_row"
to the row labels of my_series
using the add_suffix()
function. We print the result to the console.