PySpark withColumn 函数拉出某些字段
PySpark withCoumn Function to pull out certain fields
我正在尝试 select 我的数据框中的某些字段。
folloiwng printSchema() 显示了我的数据框中的字段
正在用 PySpark 编写代码
df_log.printSchema()
root
|-- load_id: integer (nullable = true)
|-- Feed_id: integer (nullable = true)
|-- Feed_source: string (nullable = true)
|-- Feed_name: string (nullable = true)
|-- Load_date: string (nullable = true)
|-- Duration_of_load: string (nullable = true)
|-- Rows_loaded: string (nullable = true)
|-- Error message: string (nullable = true)
我只想要数据集中的 'load_id' 和 'Feed_name',所以我尝试了以下操作:
df_log.withColumn(col(load_id), col(Feed_name))
但是我收到以下错误:
NameError: name 'col' is not defined
Traceback (most recent call last):
NameError: name 'col' is not defined
这是在带有 Apache Spark 池的 Azure Synapse 上 运行。
我不应该定义 'col'
对我做错了什么有什么想法吗?
你需要 select
。
df_log.select('load_id', 'Feed_name')
我正在尝试 select 我的数据框中的某些字段。
folloiwng printSchema() 显示了我的数据框中的字段
正在用 PySpark 编写代码
df_log.printSchema()
root
|-- load_id: integer (nullable = true)
|-- Feed_id: integer (nullable = true)
|-- Feed_source: string (nullable = true)
|-- Feed_name: string (nullable = true)
|-- Load_date: string (nullable = true)
|-- Duration_of_load: string (nullable = true)
|-- Rows_loaded: string (nullable = true)
|-- Error message: string (nullable = true)
我只想要数据集中的 'load_id' 和 'Feed_name',所以我尝试了以下操作:
df_log.withColumn(col(load_id), col(Feed_name))
但是我收到以下错误:
NameError: name 'col' is not defined
Traceback (most recent call last):
NameError: name 'col' is not defined
这是在带有 Apache Spark 池的 Azure Synapse 上 运行。
我不应该定义 'col'
对我做错了什么有什么想法吗?
你需要 select
。
df_log.select('load_id', 'Feed_name')