Search code examples
python-3.xpandaspython-applymap

Why doesn't the clean-up persist?


I clean a csv table. I want to delete symbols in the ID. It looks like this:

ID    Address
"(2   Hamburg
"(3   Cologne
"(4   Berlin
"(5   ...

I want to delete the "(

The code I used

Ost.applymap(lambda x: x.replace('"(', ''))

when I check the csv file after saving, the deleted symbols are back. Like nothing changed. Why is the change not saving?


Solution

  • You need to reassign the change to the variable:

    Ost = Ost.applymap(lambda x: x.replace('"(', ''))
    

    The output of:

    Ost.applymap(lambda x: x.replace('"(', ''))
    Ost
    

    is

        ID    Address
    0    (2   Hamburg
    1    (3   Cologne
    2    (4   Berlin
    

    As you can see it isn't applymap isn't make the change inplace