title: Converting Categorical Variables to Numerical Variables by using def
body: <p>I want to create a function that converts categorical variables to numerical variables. After then, I want to add one more thing, when I typed the dataframe in the function at the beginning, it has to replaces unique names with numeric values. But I have an issue while I am trying. I tried something like that:</p>
  <pre><code>def x(data):
   for col in data:
      if col.dtypes() == object:
          col.replace(list(df[col].unique()),
                      list(np.arange(data[col].nunique()), 
                      inplace = True)
  </code></pre>
  <p>Where am I wrong?</p>
  <p>Thanks in advance for your opinions.</p>