I have feature in a dataframe that stores the class information of students like:
Student_ID CLass
S1 5
S2 7
S3 6
How can I prefix characters like C_ before the Class for every student?
I have feature in a dataframe that stores the class information of students like:
Student_ID CLass
S1 5
S2 7
S3 6
How can I prefix characters like C_ before the Class for every student?
It sounds like you're looking for pd.Series.apply. Typically, it can be faster to use the special string methods for Series of strings, but I can't think of an easy way to leverage those for prepending.
>>> df = pd.DataFrame({"Student_ID": ["S1", "S2", "S3"], "Class":[5,7,6]})
>>> df
Student_ID Class
0 S1 5
1 S2 7
2 S3 6
>>> df['Class'] = df['Class'].astype(str)
>>> df['Class'] = df['Class'].apply(lambda n: 'C_' + n)
>>> df
Student_ID Class
0 S1 C_5
1 S2 C_7
2 S3 C_6