Pandas – modify cell if match and if not match delete row

Question:

i need modify a csv file with pandas, I have the following table:

Interface       Description
Gi0/3/4/3       ISP
Gi0/3/4/3.401   Cliente A
Gi0/3/4/3.402   Cliente B
Gi0/3/4/3.403   Cliente C
Gi0/3/4/4       Cliente D
Gi0/3/4/4.1     Cliente E
Gi0/3/4/4.2     Cliente F
Gi0/3/4/5       Cliente G

I need to modify the Interface column, if the cell matches Gi0/3/4/3. I need to remove this part of the string and leave the rest and if it doesn’t match Gi0/3/4/3. delete the row and finally make it look like this:

Interface       Description

401         Cliente A
402         Cliente B
403         Cliente C

From already thank you very much!

Asked By: Martin Barbieri

||

Answers:

Extract the suffix after Gi0/3/4/3. and then filter by non nulls:

df.Interface = df.Interface.str.extract('Gi0/3/4/3.(d+)')
df[df.Interface.notnull()]

  Interface Description
1       401   Cliente A
2       402   Cliente B
3       403   Cliente C
Answered By: Psidom

enter image description here

Please be sure to answer the question. Provide details and share your research!

Answered By: G.G
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.