add_suffix() : suffix columns

Pandas

DataFrame.add_suffix('str')
strString to be suffixed to column names .

Using DataFrame

We are trying to change the column NAME to name1
import pandas as pd 
my_dict={'NAME':['Ravi','Raju','Alex','Ron','King','Jack'],
         'ID':[1,2,3,4,5,6],'MATH':[30,40,50,60,70,80],
         'ENGLISH':[20,30,40,50,60,70]}
my_data = pd.DataFrame(data=my_dict)
my_data=my_data.add_suffix('_Col')
print(my_data)
Output
  NAME_Col  ID_Col  MATH_Col  ENGLISH_Col
0     Ravi       1        30           20
1     Raju       2        40           30
2     Alex       3        50           40
3      Ron       4        60           50
4     King       5        70           60
5     Jack       6        80           70

Using series

my_s=pd.Series([1,5,7,9,10])
my_s=my_s.add_suffix('_Ser')
print(my_s)
Output
0_Ser     1
1_Ser     5
2_Ser     7
3_Ser     9
4_Ser    10
dtype: int64


Pandas columns() rename() add_prefix()


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer