这会得到你想要的输入:
a[0].split('"')[1].replace(",", "#")
但有些事情告诉我这不是太有用/一般。
但无论如何,此类问题的解决方案可能会涉及这两个字符串/列表方法:split 和 replace
https://docs.python.org/3/library/stdtypes.html#str.split
https://docs.python.org/3/library/stdtypes.html#str.replace
更新
所以如果你需要使用 spark RDD,你可以先使用字符串列表创建 RDD(还不是 csv)
>>> rdd = sc.parallelize(a)
>>> rdd.take(1)
['0,Italy,"Aromas include tropical fruit, broom, brimstone and dried herb. The palate isnt overly expressive, offering unripened apple, citrus and dried sage alongside brisk acidity.",Vulk\xc3\xa0 Bianco,87,,Sicily & Sardinia,Etna,,Kerin O\xe2\x80\x99Keefe,@kerinokeefe,Nicosia 2013 Vulk\xc3\xa0 Bianco (Etna),White Blend,Nicosia']
>>> processed_rdd = rdd.map(lambda row: row.split('"')[0] + row.split('"')[1].replace(",", "#") + row.split('"')[2])
>>> processed_rdd.take(1)
['0,Italy,Aromas include tropical fruit# broom# brimstone and dried herb. The palate isnt overly expressive# offering unripened apple# citrus and dried sage alongside brisk acidity.,Vulk\xc3\xa0 Bianco,87,,Sicily & Sardinia,Etna,,Kerin O\xe2\x80\x99Keefe,@kerinokeefe,Nicosia 2013 Vulk\xc3\xa0 Bianco (Etna),White Blend,Nicosia']
我做了几个假设,因为您只提供了一个示例行。
这些假设是关于这个双引号字符串" "的存在,这是需要替换逗号的列。
此外,我假设其他列中没有"。
我还假设此列在处理后不需要那些"。
解释
rdd 方法 map 会将一个函数映射到 RDD 中的每一行,map 采用的 lambda 返回新行。所以在这里我将这个替换的命令链映射到 RDD 中的每一行(然后在示例中,我 take 一个)