christhebliss
christhebliss

Reputation: 83

How can I clean prefix from my pandas dataframe?

I have an dataframe which looks like this:

ID           Name
1-10000      Max
1-11000      Peter
1-12000      Hans

And I need to clean the prefix from the ID number to get a dataframe like this:

ID           Name
10000        Max
11000        Peter
12000        Hans

Upvotes: 2

Views: 74

Answers (1)

jezrael
jezrael

Reputation: 863301

You can split by - and select by last lists for working correct if not exist - in ID:

df['ID'] = df['ID'].str.split('-').str[-1]

Upvotes: 2

Related Questions