Dio*_*nes 2 python apache-spark pyspark
我有列表列名。
columns = ['home','house','office','work']
Run Code Online (Sandbox Code Playgroud)
我想将该列表值作为“选择”数据框中的列名称传递。
我试过了...
df_tables_full = df_tables_full.select('time_event','kind','schema','table',columns)
Run Code Online (Sandbox Code Playgroud)
但我在下面收到错误..
TypeError: Invalid argument, not a string or column: ['home', 'house', 'office',
'work'] of type <class 'list'>. For column literals, use 'lit', 'array', 'struct'
or 'create_map' function.
Run Code Online (Sandbox Code Playgroud)
你能有什么想法吗?谢谢你们!
使用*before columns取消嵌套列列表并使用 in .select。
columns = ['home','house','office','work']
#select the list of columns
df_tables_full.select('time_event','kind','schema','table',*columns).show()
df_tables_full = df_tables_full.select('time_event','kind','schema','table',*columns)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4015 次 |
| 最近记录: |