使用python删除spark中的替换管道(|)符号,并将其替换为逗号(,)符号

使用python删除spark中的替换管道(|)符号,并将其替换为逗号(,)符号,python,apache-spark,Python,Apache Spark,此myRDD数据用于2行行: [u'#fields:excDate|schedDate|TZ|custID|muID|tvID|acdID|logonID|agentName|modify|exception|start|stop|LS Oracle Emp ID|Team Lead', u'06152016|06152016|CET|3|3000|1688|87||Ali, AbdElaziz|1465812004|Open|08:00|09:00|101021021|ElDeleify,Hi

myRDD
数据用于2行

[u'#fields:excDate|schedDate|TZ|custID|muID|tvID|acdID|logonID|agentName|modify|exception|start|stop|LS Oracle Emp ID|Team Lead', u'06152016|06152016|CET|3|3000|1688|87||Ali, AbdElaziz|1465812004|Open|08:00|09:00|101021021|ElDeleify,Hisham']
如何用
替换
,以便构建
数据帧。

有没有更好的方法用这些数据构建
数据框架

它甚至不需要for循环,假设您的字符串名为“data”:

>>> data = [u'#fields:excDate|schedDate|TZ|custID|muID|tvID|acdID|logonID|agentName|modify|exception|start|stop|LS Oracle Emp ID|Team Lead', u'06152016|06152016|CET|3|3000|1688|87||Ali, AbdElaziz|1465812004|Open|08:00|09:00|101021021|ElDeleify,Hisham']
>>> data = [item.replace("|", ",") for item in data]
>>> data
['#fields:excDate,schedDate,TZ,custID,muID,tvID,acdID,logonID,agentName,modify,exception,start,stop,LS Oracle Emp ID,Team Lead', '06152016,06152016,CET,3,3000,1688,87,,Ali, AbdElaziz,1465812004,Open,08:00,09:00,101021021,ElDeleify,Hisham']
data[0] = data[0].replace('|',',')
在一行中做得很好很容易

创建帧的一种方法是将数据作为列表传递,将标题作为列表传递

data = [u'#fields:excDate|schedDate|TZ|custID|muID|tvID|acdID|logonID|agentName|modify|exception|start|stop|LS Oracle Emp ID|Team Lead', u'06152016|06152016|CET|3|3000|1688|87||Ali, AbdElaziz|1465812004|Open|08:00|09:00|101021021|ElDeleify,Hisham']

data = [d.split("|") for d in data] #creating a list of list 

shema = data[0] # the first row of the data is the in reality the schema
data = data[1:] # remove the schema from the data
schema[0] =schema[0].split(":",1)[1] #to remove the #fields: of the first header
dataframe = sqlContext.createDataFrame(data,schema)

u'xxx'
提示python v2,ok。如果您只是需要替换,为什么不在显示的列表中使用它呢?比如说
myRDD
,然后
[z.replace('|',',')为myRDD中的z]
应该给出一个新的列表,其中的stings都有逗号而不是管道。任何特定的问题都可以由其他人更好地回答;-)谢谢现在下一个问题是如何用它来构建数据框架。因为列代理名称和团队负责人包含“,”。实际上我对spark或dataframes之类的东西一无所知。我只知道如何操作字符串。谢谢,这个解决方案只适用于单行。但问题是如何替换为多行。@SamirMatkar不客气,行是指字符串吗?