I have a column with strings. I want to split and create a new column in the dataframe.
For example:
2022-01-28 15-43-45 150
I want to split after 45
and create a new column.
CodePudding user response:
We can use str.extract
here:
df["new_col"] = df["filename"].str.extract(r'(\d )$')
df["filename"] = df["filename"].str.extract(r'(.*)\s \d $')