TransWikia.com

SyntaxError: only named arguments may follow *expression - How to do in Python 2

Stack Overflow Asked on November 10, 2021

My Python version is 2.7 and I am using this code:

 df1.select(*[x for x in df1.columns if x!='fields'], F.col("fields.*")).show()

But I got this error:

  File "<ipython-input-16-3d81a8b987ed>", line 1
    df1.select(*[x for x in df1.columns if x!='fields'], F.col("fields.*")).show()
SyntaxError: only named arguments may follow *expression

How can I modify my code to make it work in Python 2? Thanks.

2 Answers

Try by passing col on both of your expressions in .select

df1.select(*[F.col(x) for x in df1.columns if x!='fields'], F.col("fields.*")).show()

#or without col in .select

df.select("fields.*",*[x for x in df.columns if x !='fields']).show()

Answered by notNull on November 10, 2021

Try appending your select expression to list comprehension.

expr = [x for x in df1.columns if x!='fields']+[F.col("fields.*")]
df1.select(*expr).show()

Answered by Raghu on November 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP