title: Why does pyspark agg tell me that datatypes are incorrect here?
body: <p>I have a dataframe with the folowing types:</p>
  
  <pre><code>&gt;&gt;&gt; mydf.printSchema()
  root
   |-- protocol: string (nullable = true)
   |-- source_port: long (nullable = true)
   |-- bytes: long (nullable = true)
  </code></pre>
  
  <p>And when I try to aggregate it like this:</p>
  
  <pre><code>df_agg = mydf.groupBy('protocol').agg(sum('bytes'))
  </code></pre>
  
  <p>I am being told:</p>
  
  <pre><code>TypeError: unsupported operand type(s) for +: 'int' and 'str'
  </code></pre>
  
  <p>Now, this does not make sense to me, since I see the types are fine for aggregation in <code>printSchema()</code> as you can see above.</p>
  
  <p>So, I tried converting it to integer just incase:</p>
  
  <pre><code>mydf_converted = mydf.withColumn("converted",mydf["bytes_out"].cast(IntegerType()).alias("bytes_converted"))
  </code></pre>
  
  <p>but still failure:</p>
  
  <pre><code>my_df_agg_converted = mydf_converted.groupBy('protocol').agg(sum('converted'))
  
  TypeError: unsupported operand type(s) for +: 'int' and 'str'
  </code></pre>
  
  <p>How to fix it?  I looked at this question, but the fix did not help me at all - same issue:
  <a href="https://stackoverflow.com/questions/36719039/sum-operation-on-pyspark-dataframe-giving-typeerror-when-type-is-fine">Sum operation on PySpark DataFrame giving TypeError when type is fine</a></p>