title: Python 3 function to loop over pandas data frame to change schema
body: <p>I'm converting a bunch of pandas data frames into spark df then writing to hdfs. Also explicitly specifying the schema to change all data types into string to avoid the merge class conflict. </p>
  
  <p>Trying to write a function that will loop through all the pandas df columns, create the schema then I can use the schema to convert to spark. </p>
  
  <p>Here is what I have so far: </p>
  
  <pre><code>def creating_schema(df):
      for columnName in df.columns:
          schema = StructType([(StructField('"' + columnName + '"' , StringType(), True))])
          print(schema)
  
      return(schema)
  </code></pre>
  
  <p>This outputs:</p>
  
  <pre><code>StructType(List(StructField("column_1",StringType,true)))
  StructType(List(StructField("column_2",StringType,true)))
  StructType(List(StructField("column_3",StringType,true)))
  StructType(List(StructField("column_4",StringType,true)))
  StructType(List(StructField("column_5",StringType,true)))
  </code></pre>
  
  <p>However, I believe I need something in this format for it to work:</p>
  
  <pre><code>schema = StructType([StructField("column_1" , StringType(), True),
                      StructField("column_2" , StringType(), True),
                      StructField("column_3" , StringType(), True),
                      StructField("column_4" , StringType(), True),
                      StructField("column_5" , StringType(), True)
                      ])
  </code></pre>
  
  <p>Any help in writing this function would be helpful! </p>
  
  <p>Thanks!</p>