簡體   English   中英

如何從pyspark數據幀中將列值輸出為字符串?

[英]How to output column values from pyspark dataframe into string?

我正在使用數據集,並想創建一個名為'text'的特定列的所有值的textblob。 我嘗試了以下方法:

xp = positive.select("text").collect().map(_(0)).toList
#positive is the dataframes name, 'text' is the column name
xp = " ".join(positive['text])

到目前為止,這些方法都沒有對我有用,並且返回錯誤

'list' object has no attribute 'map'
Traceback (most recent call last):
AttributeError: 'list' object has no attribute 'map'

您似乎正在使用Scala語法。 collect返回的list包含Row對象; 您可以使用生成器表達式簡單地訪問每個Rowtext屬性,而不是使用map (在任何情況下都不是list的方法):

' '.join(row.text for row in positive.select('text').collect())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM