0
我是新來的火花。我有一個火花數據幀:從數據框中獲取唯一密鑰
print(df)
[Row(feature=Row(a=u'enabled', b=None, c=None, d=u'enabled', e=None, f=None)),
Row(feature=Row(a=None, b=None, c=None, d=u'enabled', e=None, f=None))]
我試圖獲取列表
experiments = [a, b, c, d, e]
我已經嘗試了所有的功能名稱:
a = df.rdd.map(lambda r: r.feature).collect()
這給我的所有鍵和值對。
即。
[Row(a=u'enabled', b=None, c=None, d=u'enabled', e=None, f=None), Row(a=None, b=None, c=None, d=u'enabled', e=None, f=None)]
如何在上述步驟後獲得不同的功能列表或者是否有其他優雅的解決方案?
即
final_list = [a, b, c, d, e, f]
它說:AttributeError的:「名單」對象有沒有屬性「列」 – SpaceOddity
@SpaceOddity因爲地方在你的代碼轉換
您也可以通過轉換行到字典中按如下方式訪問鍵你的數據框到一個列表中。樣本'df'是一個列表。查看我更新的答案,以獲取從列表中訪問密鑰的另一種方式。 – MedAli