Reputation: 694
I have a tuple with the following structure and it's and RDD:
[('M', 0.016200000000000003), ('H', 0.0165), ('M', 0.0161), ('M', 0.0168), ('H', 0.0167), ('M', 0.0165), ('M', 0.0165), ('H', 0.018000000000000002), ('H', 0.0172), ('H', 0.0182), ('M', 0.0167), ('H', 0.0187), ('M', 0.016399999999999998), ('M', 0.0167), ('M', 0.0165), ('H', 0.0168), ('M', 0.0161), ('H', 0.0168), ('M', 0.0159)]
The first part, the key is "H" man or "M" women, and the other part, the value is their size in KM.
What I want is to access to each of the values from each key and multiply it by 10000.
Here is my code.
to_float1 = to_float.map(lambda x: x[1]*10000)
And the output:
[162.00000000000003, 165.0, 161.0, 168.0, 167.0, 165.0, 165.0, 180.00000000000003, 172.0, 182.0, 167.0, 187.0, 163.99999999999997, 167.0, 165.0, 168.0, 161.0, 168.0, 159.0]
My problem as you can see is that I'm losing the key's part from my tuple.
Any idea for maintaining the tuple structure?
Upvotes: 1
Views: 78
Reputation: 6129
Have you tried returning a tuple from your lambda?
to_float1 = to_float.map(lambda x: (x[0], x[1]*10000))
Upvotes: 2