Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I select specific charcter using Python Regex

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading