How do I replace ‘.’ in a dataframe if it’s the only value in a cell without also replacing it if it’s part of a decimal number?
Here’s the dataframe
| id |
|---|
| 2.2222 |
| . |
| . |
| 3.2 |
| 1.0 |
I tried this but it removes all decimals
df = pd.DataFrame({'id':['2.2222','.','.','3.2','1.0']})
df['id'] = df['id'].str.replace('.','',regex=False)
Unwanted result:
| id |
|---|
| 22222 |
| 32 |
| 10 |
This is the desired result:
| id |
|---|
| 2.2222 |
| 3.2 |
| 1.0 |
>Solution :
You could use .loc to do the replace:
df.loc[df['id'] == '.', 'id'] = ''