title: How to replace 'any strings' with nan in pandas DataFrame using a boolean mask?
body: <p>I have a 227x4 DataFrame with country names and numerical values to clean (wrangle ?).</p>
  
  <p>Here's an abstraction of the DataFrame:</p>
  
  <pre><code>import pandas as pd
  import random
  import string
  import numpy as np
  pdn = pd.DataFrame(["".join([random.choice(string.ascii_letters) for i in range(3)]) for j in range (6)], columns =['Country Name'])
  measures = pd.DataFrame(np.random.random_integers(10,size=(6,2)), columns=['Measure1','Measure2'])
  df = pdn.merge(measures, how= 'inner', left_index=True, right_index =True)
  
  df.iloc[4,1] = 'str'
  df.iloc[1,2] = 'stuff'
  print(df)
  
    Country Name Measure1 Measure2
  0          tua        6        3
  1          MDK        3    stuff
  2          RJU        7        2
  3          WyB        7        8
  4          Nnr      str        3
  5          rVN        7        4
  </code></pre>
  
  <p>How do I replace string values with <code>np.nan</code> in all columns without touching the country names?</p>
  
  <p>I tried using a boolean mask:</p>
  
  <pre><code>mask = df.loc[:,measures.columns].applymap(lambda x: isinstance(x, (int, float))).values
  print(mask)
  
  [[ True  True]
   [ True False]
   [ True  True]
   [ True  True]
   [False  True]
   [ True  True]]
  
  # I thought the following would replace by default false with np.nan in place, but it didn't
  df.loc[:,measures.columns].where(mask, inplace=True)
  print(df)
  
    Country Name Measure1 Measure2
  0          tua        6        3
  1          MDK        3    stuff
  2          RJU        7        2
  3          WyB        7        8
  4          Nnr      str        3
  5          rVN        7        4
  
  
  # this give a good output, unfortunately it's missing the country names
  print(df.loc[:,measures.columns].where(mask))
  
    Measure1 Measure2
  0        6        3
  1        3      NaN
  2        7        2
  3        7        8
  4      NaN        3
  5        7        4
  </code></pre>
  
  <p>I have looked at several questions related to mine (<a href="https://stackoverflow.com/questions/44440991/pandas-dataframe-boolean-mask-on-multiple-columns">[1]</a>, <a href="https://stackoverflow.com/questions/30519140/pandas-dataframe-set-value-on-boolean-mask">[2]</a>, <a href="https://stackoverflow.com/questions/13842088/set-value-for-particular-cell-in-pandas-dataframe?s=1|181.1213">[3]</a>, <a href="https://stackoverflow.com/questions/13842088/set-value-for-particular-cell-in-pandas-dataframe">[4]</a>, <a href="https://stackoverflow.com/questions/17383094/python-pandas-numpy-true-false-to-1-0-mapping?s=1|94.6631">[5]</a>, <a href="https://stackoverflow.com/questions/29686046/python-pandas-filter-method-using-boolean-mask?s=1|69.9785">[6]</a>, <a href="https://stackoverflow.com/questions/42035652/how-to-load-an-excel-sheet-and-clean-the-data-in-python?s=1|33.3427">[7]</a>, <a href="https://stackoverflow.com/questions/37837148/replaces-spaces-with-nan-in-pandas-dataframe">[8]</a>), but could not find one that answered my concern.</p>