1

I have a df

Name Zone                                                    Dummy
A    BARI (BA), BARLETTA (BT), BRINDISI (BR), FOGGIA (FG)     2
B    BARI (BA), FOGGIA (FG)                                   2
C    HDEF (SE), LECCE (LE)                                    3
D    GUVA (PP)                                                3

I need df as

    Name Zone                                             Symbol            Dummy
    A    BARI , BARLETTA , BRINDISI , FOGGIA         (BA),(BT),(BR),(FG)      2
    B    BARI , FOGGIA                               (FG),(BA)                2
    C    HDEF , LECCE                                (LE),(SE)                3
    D    GUVA                                        (PP)                     3

Tried to split the Zone and Symbol using

Series.str.split()

but not working as expected.

1 Answer 1

1

You could use str.replace here:

df["Symbol"] = df["Zone"].str.replace(r'(?:|\s+)[A-Z]+\s+', '')
df["Zone"] = df["Zone"].str.replace(r'\s*\(.*?\)\s*', '')
Sign up to request clarification or add additional context in comments.

4 Comments

Its not working..
yes working, how to remove duplicates..! like there is two same symbols..
That's not your original question. You should either edit your current question or ask a new one.
ok thank u, this is sufficient for now..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.