0

I wrote 2 very similar codes to replace characters (?, .) to nan values in Python. Unfortunately one of them worked perfectly but other did not. Here are the codes

df_train['SES'].replace('?',np.nan, inplace= True)

That worked perfectly, but

df_train['CLUSTER_CODE'].replace('.', np.nan, inplace= True)

this one is very similar code to above, but did not work. Any advice please as i'm very new to python and trying to learn.

Alireza
  • 656
  • 1
  • 6
  • 20
S. Mandal
  • 71
  • 9
  • Are you sure here are `'.'` values in he second column? can you print the value of `len(df_train[df_train['CLUSTER_CODE']=='.'])`? – Alireza Jun 12 '20 at 12:04
  • Please provide a small set of sample data as text that we can copy and paste. Include the corresponding desired result. Check out the guide on [how to make good reproducible pandas examples](https://stackoverflow.com/a/20159305/3620003). – timgeb Jun 12 '20 at 12:06
  • Not a `machine-learning` question - kindly do not spam irrelevant tags (removed). – desertnaut Jun 12 '20 at 12:08
  • Hi, thanks for taking notice. and I am sure in the column it is as . – S. Mandal Jun 12 '20 at 12:10
  • @Alireza, here i'm pasting all the unique numbers of the column just to make sence – S. Mandal Jun 12 '20 at 12:27
  • 51 457 14 451 . 446 41 427 16 383 – S. Mandal Jun 12 '20 at 12:27
  • It worked for me. I used `pd.DataFrame(['1', '2', '.', '3']).replace('.', np.nan)inplace=True)`. What error are you getting? – Hell stormer Jun 12 '20 at 13:26
  • Here is a crazy idea! instead of writing the dot using your keyboard in your python code, copy-paste the value from your table directly... I suggest this because there are multiple chars rendered as dot, but slightly different (in code). I had the same problem once. – Alireza Jun 12 '20 at 13:34
  • Thanks, this crazy idea actually worked, I did copy-paste the value from the table directly and it appeared to be working. thank you much @ Alireza – S. Mandal Jun 16 '20 at 09:32

0 Answers0