title: How to change dataframe column names in PySpark?
body: <p>I come from pandas background and am used to reading data from CSV files into a dataframe and then simply changing the column names to something useful using the simple command:</p>
  <pre><code>df.columns = new_column_name_list
  </code></pre>
  <p>However, the same doesn't work in PySpark dataframes created using sqlContext.
  The only solution I could figure out to do this easily is the following:</p>
  <pre><code>df = sqlContext.read.format(&quot;com.databricks.spark.csv&quot;).options(header='false', inferschema='true', delimiter='\t').load(&quot;data.txt&quot;)
  oldSchema = df.schema
  for i,k in enumerate(oldSchema.fields):
    k.name = new_column_name_list[i]
  df = sqlContext.read.format(&quot;com.databricks.spark.csv&quot;).options(header='false', delimiter='\t').load(&quot;data.txt&quot;, schema=oldSchema)
  </code></pre>
  <p>This is basically defining the variable twice and inferring the schema first then renaming the column names and then loading the dataframe again with the updated schema.</p>
  <p>Is there a better and more efficient way to do this like we do in pandas?</p>
  <p>My Spark version is 1.5.0</p>