Reputation: 3667
I have df columns that looks like this:
string1_0_string2_string3 string2_0_0_1_string4
1 1
I want to only keep the name after the last underscore _
in the column name, how would I do this?
New df should look like this:
string3 string4
1 1
Upvotes: 1
Views: 305
Reputation: 323226
Using str.split
df.columns=df.columns.str.split('_').str[-1]
df
Out[183]:
string3 string4
0 1 1
Upvotes: 3