title: ValueError contains new labels when trying to label encode in python
body: <p>I have a dataset which requires label encoding. I am using sklearn's label encoder for the same.</p>
  
  <p>Here is the reproducible code for the problem:</p>
  
  <pre><code>import pandas as pd
  from sklearn.preprocessing import LabelEncoder
  
  data11 = pd.DataFrame({'Transaction_Type': ['Mortgage', 'Credit reporting', 'Consumer Loan', 'Mortgage'], 
                         'Complaint_reason': ['Incorrect Info', 'False Statement', 'Using a Debit Card', 'Payoff process'],
                         'Company_response': ['Response1', 'Response2', 'Response3', 'Response1'],
                         'Consumer_disputes': ['Yes', 'No', 'No', 'Yes'],
                         'Complaint_Status': ['Processing','Closed', 'Awaiting Response', 'Closed']
                         })
  
  le = LabelEncoder()
  data11['Transaction_Type'] = le.fit_transform(data11['Transaction_Type'])
  data11['Complaint_reason'] = le.transform(data11['Complaint_reason'])
  data11['Company_response'] = le.fit_transform(data11['Company_response'])
  data11['Consumer_disputes'] = le.transform(data11['Consumer_disputes'])
  data11['Complaint_Status'] = le.transform(data11['Complaint_Status'])
  </code></pre>
  
  <p>The desired output should be something like:</p>
  
  <pre><code>({'Transaction_Type': ['1', '2', '3', '1'], 
                         'Complaint_reason': ['1', '2', '3', '4'],
                         'Company_response': ['1', '2', '3', '1'],
                         'Consumer_disputes': ['1', '2', '2', '1'],
                         'Complaint_Status': ['1','2', '3', '2']
                         })
  </code></pre>
  
  <p>The problem is when I try to encode the columns:
  'Transaction_Type' and 'Company_response' get encoded successfully but the columns 'Complaint_reason', 'Consumer_disputes' and 'Complaint_Status' throw errors. </p>
  
  <p>For 'Complaint_reason':</p>
  
  <pre><code>File "C:/Users/Ashu/untitled0.py", line 26, in &lt;module&gt;
      data11['Complaint_reason'] = le.transform(data11['Complaint_reason'])
  
  ValueError: y contains new labels: ['APR or interest rate' 'Account opening, closing, or management'
   'Account terms and changes' ...
   "Was approved for a loan, but didn't receive the money"
   'Written notification about debt' 'Wrong amount charged or received']
  </code></pre>
  
  <p>and similarly for 'Consumer_disputes':</p>
  
  <pre><code>  File "&lt;ipython-input-117-9625bd78b740&gt;", line 1, in &lt;module&gt;
      data11['Consumer_disputes'] = le.transform(data11['Consumer_disputes'].astype(str))
  
  ValueError: y contains new labels: ['No' 'Yes']
  </code></pre>
  
  <p>and similarly for 'Complaint_Status':</p>
  
  <pre><code>  File "&lt;ipython-input-119-5cd289c72e45&gt;", line 1, in &lt;module&gt;
      data11['Complaint_Status'] = le.transform(data11['Complaint_Status'])
  
  ValueError: y contains new labels: ['Closed' 'Closed with explanation' 'Closed with monetary relief'
   'Closed with non-monetary relief' 'Untimely response']
  </code></pre>
  
  <p>These all are categorical variables with fixed inputs in forms of sentences. Following is the data slice image:</p>
  
  <p><a href="https://i.stack.imgur.com/EekQU.png" rel="nofollow noreferrer">Categorical Data Label Encoding</a></p>
  
  <p>There are a couple of questions on this on SO but none have been answered successfully.</p>