title: Python Pandas - Changing some column types to categories
body: <p>I have fed the following CSV file into iPython Notebook:</p>
  
  <pre><code>public = pd.read_csv("categories.csv")
  public
  </code></pre>
  
  <p>I've also imported pandas as pd, numpy as np and matplotlib.pyplot as plt.  The following data types are present (the below is a summary - there are about 100 columns)</p>
  
  <pre><code>In [36]:   public.dtypes
  Out[37]:   parks          object
             playgrounds    object
             sports         object
             roading        object               
             resident       int64
             children       int64
  </code></pre>
  
  <p>I want to change 'parks', 'playgrounds', 'sports' and 'roading' to categories (they have likert scale responses in them - each column has different types of likert responses though (e.g. one has "strongly agree", "agree" etc., another has "very important", "important" etc.), leaving the remainder as int64.  </p>
  
  <p>I was able to create a separate dataframe - public1 - and change one of the columns to a category type using the following code:</p>
  
  <pre><code>public1 = {'parks': public.parks}
  public1 = public1['parks'].astype('category')
  </code></pre>
  
  <p>However, when I tried to change a number at once using this code, I was unsuccessful:</p>
  
  <pre><code>public1 = {'parks': public.parks,
             'playgrounds': public.parks}
  public1 = public1['parks', 'playgrounds'].astype('category')
  </code></pre>
  
  <p>Notwithstanding this, I don't want to create a separate dataframe with just the categories columns.  I would like them changed in the original dataframe.</p>
  
  <p>I tried numerous ways to achieve this, then tried the code here: <a href="https://stackoverflow.com/questions/15891038/pandas-change-data-type-of-columns">Pandas: change data type of columns</a>...</p>
  
  <pre><code>public[['parks', 'playgrounds', 'sports', 'roading']] = public[['parks', 'playgrounds', 'sports', 'roading']].astype('category')
  </code></pre>
  
  <p>and got the following error:</p>
  
  <pre><code> NotImplementedError: &gt; 1 ndim Categorical are not supported at this time
  </code></pre>
  
  <p>Is there a way to change 'parks', 'playgrounds', 'sports', 'roading' to categories (so the likert scale responses can then be analysed), leaving 'resident' and 'children' (and the 94 other columns that are string, int + floats) untouched please?  Or, is there a better way to do this?  If anyone has any suggestions and/or feedback I would be most grateful....am slowly going bald ripping my hair out!</p>
  
  <p>Many thanks in advance.</p>
  
  <p>edited to add - I am using Python 2.7.</p>