str | String to be prefixed to column names . |
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_prefix('Col_')
print(my_data)
Output
Col_NAME Col_ID Col_MATH Col_ENGLISH
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
my_s=pd.Series([1,5,7,9,10])
my_s=my_s.add_prefix('Ser_')
print(my_s)
Output
Ser_0 1
Ser_1 5
Ser_2 7
Ser_3 9
Ser_4 10
dtype: int64
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.