title: How can I one hot encode in Python?
body: <p>I have a machine learning classification problem with 80% categorical variables. Must I use one hot encoding if I want to use some classifier for the classification? Can i pass the data to a classifier without the encoding? </p>
  
  <p>I am trying to do the following for feature selection:</p>
  
  <ol>
  <li><p>I read the train file:</p>
  
  <pre><code>num_rows_to_read = 10000
  train_small = pd.read_csv("../../dataset/train.csv",   nrows=num_rows_to_read)
  </code></pre></li>
  <li><p>I change the type of the categorical features to 'category':</p>
  
  <pre><code>non_categorial_features = ['orig_destination_distance',
                            'srch_adults_cnt',
                            'srch_children_cnt',
                            'srch_rm_cnt',
                            'cnt']
  
  for categorical_feature in list(train_small.columns):
      if categorical_feature not in non_categorial_features:
          train_small[categorical_feature] = train_small[categorical_feature].astype('category')
  </code></pre></li>
  <li><p>I use one hot encoding: </p>
  
  <pre><code>train_small_with_dummies = pd.get_dummies(train_small, sparse=True)
  </code></pre></li>
  </ol>
  
  <p>The problem is that the 3'rd part often get stuck, although I am using a strong machine.</p>
  
  <p>Thus, without the one hot encoding I can't do any feature selection, for determining the importance of the features.</p>
  
  <p>What do you recommend?</p>