Python – How to split a Pandas value and only get the value between the slashs
Question:
Answers:
How’s about:
df['column'].map(lambda x: int(x.split('/')[1]))
You could extract
the value and convert to_numeric
:
df['number'] = pd.to_numeric(df['column'].str.extract('/(d+)/', expand=False))
Example:
column number
0 F/4500/O 4500
1 G/2/P 2
How’s about:
df['column'].map(lambda x: int(x.split('/')[1]))
You could extract
the value and convert to_numeric
:
df['number'] = pd.to_numeric(df['column'].str.extract('/(d+)/', expand=False))
Example:
column number
0 F/4500/O 4500
1 G/2/P 2