简体   繁体   中英

How to remove brackets from RDD output?

When I print an RDD I get the following result:

[(46, u'15910'), (43, u'15287'), (43, u'15237'), (42, u'15923'), (41, u'15298')]

I want to save the RDD output to a csv file without brackets or the 'u' sign, similar to below:

46, 15910
43, 15287
43, 15237
42, 15923
41, 15298

Either write csv:

>>> rdd.toDF().write.csv("path")

or format:

>>> rdd.map(lambda (k, v): "{0},{1}".format(k, v)).saveAsTextFile("path")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM