Code before rstrip
column_names = lh_Area_Base_V2.columns.tolist()
for i, val in enumerate(column_names[1:]):
column_names[i+1] += '_Base_V2'
column_names[0] = 'Subj_ID'
# Replace the column names with a new name
lh_Area_Base_V2.columns = column_names
lh_Area_Base_V2.head()
Code with rstrip (to drop "_V2" from the end of first column values):
column_names = lh_Area_Base_V2.columns.tolist()
for i, val in enumerate(column_names[1:]):
column_names[i+1] += '_Base_V2'
column_names[0] = 'Subj_ID'
lh_Area_Base_V2['Subj_ID'] = lh_Area_Base_V2['Subj_ID'].map(lambda x: x.lstrip().rstrip('_V2'))
# Replace the column names with a new name
lh_Area_Base_V2.columns = column_names
lh_Area_Base_V2.head()
Error: Why does ID index #1 have a value 2 dropped at the end, which was not requested by the rstrip function (the function only requested for "_V2" to be dropped)?
I would love to hear any suggestions for fixes.