[英]Getting 'list' object has no attribute 'tolist' in python
I am trying to run pyspark script.我正在尝试运行 pyspark 脚本。 In this script i am executing sql query and creating dataframe after i am trying to change last column position into first but it is giving me error.
在这个脚本中,我正在执行 sql 查询并在我尝试将最后一列 position 更改为第一列之后创建 dataframe 但它给了我错误。 Can you please help me how to do this?
你能帮我怎么做吗?
code:代码:
if(masterjobname.endswith('ADDR_Phani')):
df = sqlContext.sql(query)
print("Target: "+targetpath )
w = (Window().orderBy("SOURCE_COLUMN_VALUE"))
df = df.withColumn("SYSTEM_ID", dense_rank().over(w))
cols = df.columns.tolist()
cols = cols[-1:] + cols[:-1]
df = df[cols]
Okay i got the answer.好的,我得到了答案。
df.columns.values.tolist()
gives the list of the columns. df.columns.values.tolist()
给出列的列表。
solution:解决方案:
if(masterjobname.endswith('ADDR_Phani')):
df = sqlContext.sql(query)
print("Target: "+targetpath )
w = (Window().orderBy("SOURCE_COLUMN_VALUE"))
df = df.withColumn("SYSTEM_ID", dense_rank().over(w))
cols = df.columns.values.tolist()
cols = cols[-1:] + cols[:-1]
df = df[cols]
No matter if your variable is or isn't a list:无论您的变量是或不是列表:
list(var)
You can use it as exception handling;您可以将其用作异常处理; ie ensure that it is indeed a list object.
即确保它确实是一个列表 object。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.