My input dataframe is
NODE | SPEED | PACKETLINK
-----------------------
MUMDSP | 511.054 | CT 1/12/1;CT 1/12/2
MUMDSP | 154.155 | 1/3/1
soemfe01 | 76.065 | 1/20 21/1
soemfe01 | 187.959 1/8 9/1
MUMDSP | 224.949 | 1/3/1
MUMDSP | 450 | CT 1/1/1;CT 1/1/2
and my Output dataframe would be
NODE | SPEED | PACKETLINK | SLOT
-----------------------
MUMDSP | 511.054 | CT 1/12/1;CT 1/12/2 | 12
MUMDSP | 154.155 | 1/3/1 | 3
soemfe01 | 76.065 | 1/20 21/1 | 20 21
soemfe01 | 187.959 1/8 9/1 | 8 9
MUMDSP | 224.949 | 1/3/1 | 3
MUMDSP | 450 | CT 1/1/1;CT 1/1/2 | 1
please help on this.
CodePudding user response:
Try:
df['SLOT'] = df['PACKETLINK'].str.extract('/([^/] )/')
print(df)
# Output:
NODE SPEED PACKETLINK SLOT
0 MUMDSP 511.054 CT 1/12/1;CT 1/12/2 12
1 MUMDSP 154.155 1/3/1 3
2 soemfe01 76.065 1/20 21/1 20 21
3 soemfe01 187.959 1/8 9/1 8 9
4 MUMDSP 224.949 1/3/1 3
5 MUMDSP 450.000 CT 1/1/1;CT 1/1/2 1