Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pyspark 我有一张桌子;t';有两列';col24';和';col23';我想创建一个数据帧';r';_Pyspark_Pyspark Sql - Fatal编程技术网

Pyspark 我有一张桌子;t';有两列';col24';和';col23';我想创建一个数据帧';r';

Pyspark 我有一张桌子;t';有两列';col24';和';col23';我想创建一个数据帧';r';,pyspark,pyspark-sql,Pyspark,Pyspark Sql,假设一个表t有两列--col24和col18我想创建一个数据帧'r'。这样生成的数据帧将只有一列col24名为first\u name 我已经尝试了以下代码,但它不工作。但我得到它不正确的帮助我解决 import pyspark.sql.functions as f r = t.select(f.explode("col24").alias("first_name")).toPandas() 如果我正确理解了你的问题,这两个选项应该有效: r = t.select('col24').f.

假设一个表
t
有两列--
col24
col18
我想创建一个数据帧'r'。这样生成的数据帧将只有一列
col24
名为
first\u name

我已经尝试了以下代码,但它不工作。但我得到它不正确的帮助我解决


import pyspark.sql.functions as f

r = t.select(f.explode("col24").alias("first_name")).toPandas()

如果我正确理解了你的问题,这两个选项应该有效:

r = t.select('col24').f.withColumnRenamed('col24', 'first_name')

r = t.withColumnRenamed('col24', 'first_name').drop('col18')
例如,如果列表中有多个列,则第二个选项变为:

r = t.withColumnRenamed('col24', 'first_name').drop(*my_cols)
然后,您可以检查数据帧:

r.show()
或者,如果t很大,只需检查列名称:

r.columns

请在下面找到您期望的答案:

select(f.col("col24").alias("first_name"))

您有两列
col24
col18
。1) 您想将
col24
重命名为
first\u name
2)您想删除
col18
。这是你想要的吗?是的,我也需要。
select(f.col("col24").alias("first_name"))