我收到这个错误pyspark.sql.utils.Illegal Argument Exception: requirement failed: The number of columns doesn't match.
旧列名(6):vin
、age
、var
、rim
、cap
、cur
新列名(2):vin
,age
用于以下代码:
schema = StructType([
StructField( 'vin', StringType(), True),StructField( 'age', IntegerType(), True),StructField( 'var', IntegerType(), True),StructField( 'rim', IntegerType(), True),StructField( 'cap', IntegerType(), True),StructField( 'cur', IntegerType(), True)
])
data = [['tom', 10,54,87,23,90], ['nick', 15,63,23,11,65], ['juli', 14,87,9,43,21]]
df=spark.createDataFrame(data,schema)
use=['vin','age']
df1=df.toDF(*use)
df1.show()
要使用列名列表从数据帧中选择某些列,请使用
select
,而不是toDF
:toDF
仅适用于重命名数据帧中的所有列。它不适合选择某些列相关问题 更多 >
编程相关推荐