0

문자열이 포함 된 열이있는 pyspark 데이터 프레임이 있습니다.PySpark 데이터 프레임의 문자열 열 분할 내용

>>> sentenceData = sqlContext.read.load('file://sample1.csv', format='com.databricks.spark.csv', header='true', inferSchema='true') 
>>> sentenceData.show(truncate=False) 
+---+---------------------------+ 
|key|desc      | 
+---+---------------------------+ 
|1 |Virat is good batsman  | 
|2 |sachin was good   | 
|3 |but modi sucks big big time| 
|4 |I love the formulas  | 
+---+---------------------------+ 


Expected Output 
--------------- 

>>> sentenceData.show(truncate=False) 
+---+-------------------------------------+ 
|key|desc         | 
+---+-------------------------------------+ 
|1 |[Virat,is,good,batsman]    | 
|2 |[sachin,was,good]     | 
|3 |....         | 
|4 |...         | 
+---+-------------------------------------+ 

어떻게 이것을 달성 할 수있다 : 나는

코드 단어

에이 열을 분할 할?

답변

3

사용 split 기능 :

from pyspark.sql.functions import split 

df.withColumn("desc", split("desc", "\s+")) 
관련 문제