I have a dataset where I would like to create a new column derived from one of my existing columns. The new column is created by taking the values after the first colon up until, and not including the last colon.
Data
site stat crate
JJ - site 1 ok JD1:0055:AB5.30:100
JJ - site 1 ok JD1:00AB:AB5.30:111
J1 - site 2 fail JD1:00AA:AB5.30:200
JJ - site 1 ok JD1:00A:AB5.30:555
CC - site 8 fail CC5:01AAA:BA8.40:777
Desired
site stat main_cr crate
JJ - site 1 ok 0055:AB5.30 JD1:0055:AB5.30:100
JJ - site 1 ok 00AB:AB5.30 JD1:00AB:AB5.30:111
J1 - site 2 fail 00AA:AB5.30 JD1:00AA:AB5.30:200
JJ - site 1 ok 00A:AB5.30 JD1:00A:AB5.30:555
CC - site 8 fail 01AAA:BA8.40 CC5:01AAA:BA8.40:777
Doing
df['main_cr']=df['crate'].str.extract(r':(\d):.*):')
I've read the documentation but am a little stuck on the placement of the extraction steps Any suggestion is helpful thank you.