| 矩陣(型別陣列) |
|---|
| [TKI1] |
| [TKI4] |
我會得到這個資料框
| 矩陣(型別字串) |
|---|
| TKI1 |
| TKI4 |
uj5u.com熱心網友回復:
因為你Marticule是ArrayType一開始的。您可以直接使用getItem如下 -
資料準備
df = pd.DataFrame({
'Matricule':[['TKI1'],['TKI4']],
})
sparkDF = sql.createDataFrame(df)
sparkDF.show()
---------
|Matricule|
---------
| [TKI1]|
| [TKI4]|
---------
sparkDF.printSchema()
root
|-- Matricule: array (nullable = true)
| |-- element: string (containsNull = true)
獲取專案
sparkDF = sparkDF.withColumn('Matricule_string',F.col('Matricule').getItem(0))
sparkDF.show()
--------- ----------------
|Matricule|Matricule_string|
--------- ----------------
| [TKI1]| TKI1|
| [TKI4]| TKI4|
--------- ----------------
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/433537.html
標籤:数据框 阿帕奇火花 pyspark apache-spark-sql
上一篇:獲取每行的第二個非空白列的名稱
