how do I cast field from double to float and round it using pyspark
<p>I have two dataframes with the schema as below:
books_with_10_ratings_or_more_with_title:</p>

<pre><code>root
 |-- ISBN: string (nullable = true)
 |-- count: long (nullable = false)
 |-- average: double (nullable = true)
</code></pre>

<p>and 
books_df:</p>

<pre><code>root
 |-- ISBN: string (nullable = true)
 |-- count: long (nullable = false)
 |-- average: double (nullable = true)
</code></pre>

<p>I tried to join them together and change the rating(i.e. average) to float </p>

<pre><code>books_with_10_ratings_or_more_with_title = books_with_10_ratings_or_more.join(books_df, 'ISBN').select('ISBN', 'Book-Title', 'Book-Author', 'Year', books_with_10_ratings_or_more.average.cast(float))
</code></pre>

<p>so I can round it with the following code, it throws an error:</p>

<p><a href="http://i.stack.imgur.com/VDS5l.jpg" rel="noreferrer">unexpected type: </a></p>

<p>What's wrong with the code and how do I fix it? Thank you very much.</p>