title: Running a function if dtype is equal to object
body: <p>I am experimenting with some functions in pandas and I am trying to run test() on a data frame and have test() create dummy variables if the data frame contains dtypes that are equal to objects. </p>
  
  <p>I am able to get the function to print out a np arrary with the dummy vars, but I cant seem to get it to overwrite the df that I read into test()</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import os
  
  url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/communities/communities.data'
      df = pd.read_csv(url, sep=',', header=0, names=names, na_values='?')
      df.head(2) 
  
  def test(data):
      for i in data.columns:
          if data[i].dtype == 'object':
              list_ = list(data.select_dtypes(include=['object']).columns)
              #print list_
              data = pd.get_dummies(data, prefix=list_)
              return data
  #test(df)
  #df = df.apply(test, axis =1)
  df.apply(test)
  #df.head(2)
  </code></pre>
  
  <blockquote>
    <p>AttributeError: ("'Series' object has no attribute 'columns'",
    u'occurred at index state')</p>
  </blockquote>