PySpark: How to write a Spark dataframe having a column with type SparseVector into CSV file?
<p>I have a spark dataframe which has one column with type spark.mllib.linalg.SparseVector:</p>

<p>1) how can I write it into a csv file?</p>

<p>2) how can I print all the vectors?</p>

<ol>
<li><a href="https://github.com/databricks/spark-csv" rel="nofollow">https://github.com/databricks/spark-csv</a></li>
<li><p><code>df2 = df1.map(lambda row: row.yourVectorCol)</code></p>

<p>OR <code>df1.map(lambda row: row[1])</code></p>

<p>where you either have a named column or just refer to the column by its position in the row.</p>

<p>Then, to <em>print</em> it, you can <code>df2.collect()</code></p></li>
</ol>

<p>Without more information, this may be helpful to you, or not helpful enough to you. Please elaborate a bit.</p>

python apache-spark pyspark