【发布时间】:2021-08-10 19:21:17
【问题描述】:
我的RDD如下:
uplherc.upl.com [01/Aug/1995:00:00:07] "GET /" 304 0
uplherc.upl.com [01/Aug/1995:00:00:08] "GET /images/ksclogo-medium.gif" 304 0
uplherc.upl.com [01/Aug/1995:00:00:08] "GET /images/MOSAIC-logosmall.gif" 304 0
uplherc.upl.com [01/Aug/1995:00:00:08] "GET /images/USA-logosmall.gif" 304 0
ix-esc-ca2-07.ix.netcom.com [01/Aug/1995:00:00:09] "GET /images/launch-logo.gif" 200 1713
uplherc.upl.com [01/Aug/1995:00:00:10] "GET /images/WORLD-logosmall.gif" 304 0
slppp6.intermind.net [01/Aug/1995:00:00:10] "GET /history/skylab/skylab.html" 200 1687
piweba4y.prodigy.com [01/Aug/1995:00:00:10] "GET /images/launchmedium.gif" 200 11853
slppp6.intermind.net [01/Aug/1995:00:00:11] "GET /history/skylab/skylab-small.gif" 200 9202
我想检查最后一个元素(令牌)是否是连字符,如果是,则将其替换为零。我的代码如下:
def process_row(row):
words = row.replace('"', '').split(' ')
words.map(lambda row: 0 if x[5] == '-' else x[5])
return words
nasa = (
nasa_raw.flatMap(process_row)
)
for row in nasa.take(5):
print(row)
当我尝试运行时出现错误object has no attribute map
我在这里缺少什么?
【问题讨论】:
标签: python apache-spark text replace str-replace