Thursday, September 4, 2025
HomeLanguagesPython | Pandas dataframe.add_suffix()

Python | Pandas dataframe.add_suffix()

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Dataframe.add_suffix() function can be used with both series as well as dataframes. add_suffix() function Concatenate suffix string with panel items names.

  • For Series, the row labels are suffixed.
  • For DataFrame, the column labels are suffixed.
Syntax: DataFrame.add_suffix(suffix)

Parameters:
suffix : string

Returns:  with_suffix: type of caller

For link to CSV file Used in Code, click here

Example #1: Suffix _col in each columns in the dataframe.




# importing pandas as pd
import pandas as pd
  
# Making data frame from the csv file
df = pd.read_csv("nba.csv")
  
# Printing the first 10 rows of
# the data frame for visualization
df[:10]





# Using add_suffix() function to 
# add '_col' in each column label
df = df.add_suffix('_col')
  
# Print the dataframe
df 


Output:

 

Example #2: Using add_suffix() with Series in pandas

add_suffix() alters the row index labels in the case of series.




# importing pandas as pd
import pandas as pd
  
# Creating a Series 
df = pd.Series([1, 2, 3, 4, 5, 10, 11, 21, 4])
  
# This will suffix '_Row' in
# each row of the series
df = df.add_suffix('_Row')
  
# Print the Series
df


Output:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32260 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6625 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6746 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6694 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS