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.
import pandas as pd
df = pd.read_csv( "nba.csv" )
df[: 10 ]
|
df = df.add_suffix( '_col' )
df
|
Output:
Example #2: Using add_suffix()
with Series in pandas
add_suffix()
alters the row index labels in the case of series.
import pandas as pd
df = pd.Series([ 1 , 2 , 3 , 4 , 5 , 10 , 11 , 21 , 4 ])
df = df.add_suffix( '_Row' )
df
|
Output:
Last Updated :
16 Nov, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...