Change values of an RDD

0

How can I change all the letters A to a 9 and all the letters B to an 8 in an RDD with a lambda function. I tried this but it does not work:

rdd.map(lambda a: 9 if a == "A" else a == a)
rdd.map(lambda a: 8 if a == 'B' else a == a)

My example rdd:

[[u'55', u'A', u'433235', u'12', u'09'], [u'2017', u'B', u'24212', u'4', u'1']]

And I would have to go to:

[[u'55', u'9', u'433235', u'12', u'09'], [u'2017', u'8', u'24212', u'4', u'1']]

Thanks in advance for your generous help.

    
asked by Rasha 22.06.2017 в 20:49
source

1 answer

0

As @FJSevilla says, map returns a new RDD, you just have to save it.
Also, the else is not a == a because that will always return True, it is simply a.

It would be something like this:

rdd_nuevo = rdd.map(lambda a: '9' if a == 'A' else a)
    
answered by 29.09.2017 в 11:34