首页 > 解决方案 > 添加字符串值的pyspark中存在的值

问题描述

我有如下字符串值。星火版本是 2.1

a=1\n2\n3\n4\n5

现在,当我给出上述值的类型时,它的处理方式如下

type(a)
<type 'str'>

现在我的逻辑需要除以 \n 并添加值 1,2,3,4,5 我的输出必须是 1,2,3,4,5 i,e 5

标签: python

解决方案


谢谢大家的支持,

我已经解决了。下面是代码

val=os.popen("impala-shell -i  d1endevclo006.europe.easyjet.local -d default -k -q 'show table stats scheama.tbl'| cut -d'|' -f4|grep -Eo '[+-]*[0-9]+'|sed '$ d'").read().strip()
//Above output will return me in string
numbers = map(int, lst)
type(numbers)
return sum(numbers)/len(numbers)

推荐阅读