I have a excel sheet similar to this, although with a lot more columns:
Team | Members |
---|---|
Team1 (553) | 95435 |
Team2 (443) | 872 |
I want to split the team column into Team and a new column, named Team ID. I currently do this with the following code:
df[['Team', 'Team ID']] = df['Team'].str.split(r"\s\(+(?=\S*$)", expand=True)
df['Team ID'] = df['Team ID'].str[:-1]
This works fine (note that Team name can include numbers, spaces and paranthesis). So while this might not be perfect, I gets the job done.
My issue is that the new column, "Team ID" is placed at the end of the dataset. So it would be "Team - Members - Team ID". While not an issue with 3 columns, sometimes there is 10 columns where 7 needs to be split.
So the question: Is there any way to split a column in 2, and place the newly created column next to the old one?