Pyspark和Python - Column不可迭代



我正在使用Python-3与Azure数据块。

我有一个数据框架。列'BodyJson'是一个json字符串,其中包含一个'vmedwifi/'的出现。我添加了一个常量字符串'vmedwifi/'作为列命名为'email_type'。

我想找到文本'vmedwifi/'与列'BodyJson'的开始位置-所有列都在同一数据框架内。我的代码如下:

我在第二行代码上得到错误'Column is not iterable'。知道我做错了什么吗?

# Weak logic to try and identify email addressess 
emailDf  = inputDf.select('BodyJson').where("BodyJson like('%vmedwifi%@%.%')").withColumn('email_type', lit('vmedwifi'))

b=emailDf.withColumn('BodyJson_Cutdown', substring(emailDf.BodyJson, expr('locate(emailDf.email_type, emailDf.BodyJson)'), 20))

TypeError: Column is not iterable
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<command-536715104422314> in <module>()
12 #emailDf1  = inputDf.select('BodyJson').where("BodyJson like('%@xxx.abc.uk%')")
13 
---> 14 b=emailDf.withColumn('BodyJson_Cutdown', substring(emailDf.BodyJson, expr('locate(emailDf.email_type, emailDf.BodyJson)'), 20))
15 
16 #inputDf.unpersist()

问题是传递给expr的文字。

我决定用一种不同的方法来解决这个问题。

最新更新