Python:从连接中提取变量

时间:2017-04-15 20:18:28

标签: python variables join

我在Spark(pySpark)中加入了两个数据集,输出看起来像这个

    (u'SomeThing', (u'ABC', u'500'))

我想做以下事情:定义一个只提取和返回ABC,500的函数。我写了一个这样的函数

       def extract_lasttwo_cols(three_cols):
       a,b,c = three_cols.split(',')
       return b,c

但是这个函数会导致错误"元组对象没有属性split()" 是否可以提取变量而不将结果保存为文本文件然后进行处理?

2 个答案:

答案 0 :(得分:1)

你的值是一个包含两个元素的元组,其中第二个元素本身就是一个元组

def extract_lasttwo_cols(three_cols):
    return three_cols[1]

答案 1 :(得分:1)

元组是不可变的。 split()适用于str种类型。

这将分别返回b和c:

def extract_lasttwo_cols(three_cols):
    b, c = three_cols[1][0], three_cols[1][1]
    return b, c