0

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?

Noel Harris
  • 97
  • 1
  • 9
  • Can you provide the code where you save your `Ost` as that sounds like the culprit of your issue. Adittionaly, can you verify that `Ost` is modified after doing `applymap`? – Šimon Kocúrek Jul 22 '19 at 19:04
  • yes, `Ost` shows me as modified after `applymap` . I thought the write mode saves it? `Ost.to_csv('ostarbeiter.csv')` – Noel Harris Jul 22 '19 at 19:08

2 Answers2

0

This might sound stupid, but have you saved the file after doing the applymap?

That might be the reason why your csv file is unchanged. The data changes in memory, but is never written into the "clean" csv file.

Šimon Kocúrek
  • 1,218
  • 1
  • 8
  • 17
0

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

braintho
  • 311
  • 1
  • 8
  • No problem. Happens to me all the time. Get in the habit of calling the DataFrame when troubleshooting code. On the surface it would seem something is going on with saving. Calling the df reveals that nothing changed with the applymap. – braintho Jul 22 '19 at 21:21