Home > Enterprise >  Rename the label names in pandas
Rename the label names in pandas

Time:10-27

I have a multiclass dataframe. The labels in the dataframe (shown in array) are like this:

[label:A,label:B,label:C,label:D,label:E,label:F,label:G,label:H,label:I]

How can I convert all of them into format:

[A,B,C,D,E,F,G,H,I]

CodePudding user response:

IIUC use:

df.columns = df.columns.str.replace('label:', '', regex=True)

Or if same values in first level of MulltiIndex:

df = df.droplevel(0, axis=1)
  • Related