title: Pyspark - TypeError: 'float' object is not subscriptable when calculating mean using reduceByKey
body: <p>my "asdasd.csv" file has the following structure.</p>
  
  <pre><code> Index,Arrival_Time,Creation_Time,x,y,z,User,Model,Device,gt
  0,1424696633908,1424696631913248572,-5.958191,0.6880646,8.135345,a,nexus4,nexus4_1,stand
  1,1424696633909,1424696631918283972,-5.95224,0.6702118,8.136536,a,nexus4,nexus4_1,stand
  2,1424696633918,1424696631923288855,-5.9950867,0.6535491999999999,8.204376,a,nexus4,nexus4_1,stand
  3,1424696633919,1424696631928385290,-5.9427185,0.6761626999999999,8.128204,a,nexus4,nexus4_1,stand
  </code></pre>
  
  <p>Ok, I get the following {key,value} tuple to operate with it.</p>
  
  <pre><code>#                                 x           y        z
  [(('a', 'nexus4', 'stand'), ((-5.958191, 0.6880646, 8.135345)))]
  #           part A (key)               part B (value) 
  </code></pre>
  
  <p>My code for calculating the mean is the following, I have to calculate the mean from each column, X, Y Z for each Key.</p>
  
  <pre><code>rdd_ori = sc.textFile("asdasd.csv") \
          .map(lambda x: ((x.split(",")[6], x.split(",")[7], x.split(",")[9]),(float(x.split(",")[3]),float(x.split(",")[4]),float(x.split(",")[5]))))
  
  meanRDD = rdd_ori.mapValues(lambda x: (x,1)) \
              .reduceByKey(lambda a, b: (a[0][0] + b[0][0], a[0][1] + b[0][1], a[0][2] + b[0][2], a[1] + b[1]))\
              .mapValues(lambda a : (a[0]/a[3], a[1]/a[3],a[2]/a[3]))
  </code></pre>
  
  <p>My problem I that I tried that code and it works fine on other PC with the same MV I'm using for developing it (PySpark Py3)</p>
  
  <p>Here is an example, that this code is correct: </p>
  
  <p><a href="https://i.stack.imgur.com/9W3lz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9W3lz.jpg" alt="enter image description here"></a></p>
  
  <p>But I don't know why I'm getting this error, important part is in <strong>Strong</strong>.</p>
  
  <blockquote>
    <blockquote>
      <p>--------------------------------------------------------------------------- Py4JJavaError                             Traceback (most recent call
      last)  in ()
            9 #sum_1 = count_.reduceByKey(lambda x, y: (x[0][0]+y[0][0],x<a href="https://i.stack.imgur.com/9W3lz.jpg" rel="nofollow noreferrer">0</a>+y<a href="https://i.stack.imgur.com/9W3lz.jpg" rel="nofollow noreferrer">0</a>,x[0][2]+y[0][2]))
           10 
      ---> 11 print(meanRDD.take(1))</p>
    </blockquote>
    
    <p>/opt/spark/current/python/pyspark/rdd.py in take(self, num)    1341<br>
    1342             p = range(partsScanned, min(partsScanned +
    numPartsToTry, totalParts))
    -> 1343             res = self.context.runJob(self, takeUpToNumLeft, p)    1344     1345             items += res</p>
    
    <p>/opt/spark/current/python/pyspark/context.py in runJob(self, rdd,
    partitionFunc, partitions, allowLocal)
        990         # SparkContext#runJob.
        991         mappedRDD = rdd.mapPartitions(partitionFunc)
    --> 992         port = self._jvm.PythonRDD.runJob(self._jsc.sc(), mappedRDD._jrdd, partitions)
        993         return list(_load_from_socket(port, mappedRDD._jrdd_deserializer))
        994 </p>
    
    <p>/opt/spark/current/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py
    in <strong>call</strong>(self, *args)    1131         answer =
    self.gateway_client.send_command(command)    1132         return_value
    = get_return_value(
    -> 1133             answer, self.gateway_client, self.target_id, self.name)    1134     1135         for temp_arg in temp_args:</p>
    
    <p>/opt/spark/current/python/pyspark/sql/utils.py in deco(*a, **kw)
         61     def deco(*a, **kw):
         62         try:
    ---> 63             return f(*a, **kw)
         64         except py4j.protocol.Py4JJavaError as e:
         65             s = e.java_exception.toString()</p>
    
    <p>/opt/spark/current/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py in
    get_return_value(answer, gateway_client, target_id, name)
        317                 raise Py4JJavaError(
        318                     "An error occurred while calling {0}{1}{2}.\n".
    --> 319                     format(target_id, ".", name), value)
        320             else:
        321                 raise Py4JError(</p>
    
    <p>Py4JJavaError: An error occurred while calling
    z:org.apache.spark.api.python.PythonRDD.runJob. :
    org.apache.spark.SparkException: Job aborted due to stage failure:
    Task 0 in stage 127.0 failed 1 times, most recent failure: Lost task
    0.0 in stage 127.0 (TID 102, localhost, executor driver): org.apache.spark.api.python.PythonException: Traceback (most recent
    call last):   File
    "/opt/spark/current/python/lib/pyspark.zip/pyspark/worker.py", line
    177, in main
        process()   File "/opt/spark/current/python/lib/pyspark.zip/pyspark/worker.py", line
    172, in process
        serializer.dump_stream(func(split_index, iterator), outfile)   File "/opt/spark/current/python/pyspark/rdd.py", line 2423, in
    pipeline_func
        return func(split, prev_func(split, iterator))   File "/opt/spark/current/python/pyspark/rdd.py", line 2423, in
    pipeline_func
        return func(split, prev_func(split, iterator))   File "/opt/spark/current/python/pyspark/rdd.py", line 346, in func
        return f(iterator)   File "/opt/spark/current/python/pyspark/rdd.py", line 1842, in
    combineLocally
        merger.mergeValues(iterator)   File "/opt/spark/current/python/lib/pyspark.zip/pyspark/shuffle.py", line
    238, in mergeValues
        <strong>d[k] = comb(d[k], v) if k in d else creator(v)   File "", line 3, in  TypeError:
    'float' object is not subscriptable</strong></p>
  </blockquote>