VOOZH about

URL: https://www.geeksforgeeks.org/pandas/python-pandas-series-add_suffix/

⇱ Python | Pandas Series.add_suffix() - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python | Pandas Series.add_suffix()

Last Updated : 28 Feb, 2019
Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.add_suffix() function is used to add suffix at the end of the index labels in the given series object.
Syntax: Series.add_suffix(suffix) Parameter : suffix : The string to add after each label. Returns : Series or DataFrame
Example #1: Use Series.add_suffix() function to add suffix at the end of each index labels in the given series object. Output :
Coca Cola 34
Sprite 5
Coke 13
Fanta 32
Dew 4
ThumbsUp 15
dtype: int64
Now we will use Series.add_suffix() function to add the suffix '_IPL 2019' at the end of each index labels in the given series object. Output :
Coca Cola_IPL 2019 34
Sprite_IPL 2019 5
Coke_IPL 2019 13
Fanta_IPL 2019 32
Dew_IPL 2019 4
ThumbsUp_IPL 2019 15
dtype: int64
As we can see in the output, the Series.add_suffix() function has successfully added the passed suffix at the end of each index labels in the given series object.   Example #2 : Use Series.add_suffix() function to add suffix at the end of each index labels in the given series object. Output :
2010-12-31 08:45:00 51
2011-12-31 08:45:00 10
2012-12-31 08:45:00 24
2013-12-31 08:45:00 18
2014-12-31 08:45:00 1
2015-12-31 08:45:00 84
2016-12-31 08:45:00 12
2017-12-31 08:45:00 10
2018-12-31 08:45:00 5
2019-12-31 08:45:00 24
2020-12-31 08:45:00 0
Freq: A-DEC, dtype: int64
Now we will use Series.add_suffix() function to add the suffix '_Date' at the end of each index labels in the given series object. Output :
2010-12-31 08:45:00_Date 51
2011-12-31 08:45:00_Date 10
2012-12-31 08:45:00_Date 24
2013-12-31 08:45:00_Date 18
2014-12-31 08:45:00_Date 1
2015-12-31 08:45:00_Date 84
2016-12-31 08:45:00_Date 12
2017-12-31 08:45:00_Date 10
2018-12-31 08:45:00_Date 5
2019-12-31 08:45:00_Date 24
2020-12-31 08:45:00_Date 0
dtype: int64
As we can see in the output, the Series.add_suffix() function has successfully added the passed suffix at the end of each index labels in the given series object.
Comment

Explore