2 回答
TA贡献2012条经验 获得超12个赞
您可以使用enumerate + f-string然后加入:
lst = ['id', 'account_id', 'lab_order_id', 'match_status', 'report_date', 'message', 'reporting_states',
'state_messages', 'overall_consistency', 'alerts', 'run_datetime_partition', 'run_datetime']
result = ', '.join([f'${i} "{e.upper()}"' for i, e in enumerate(lst, 1)])
print(result)
输出
$1 "ID", $2 "ACCOUNT_ID", $3 "LAB_ORDER_ID", $4 "MATCH_STATUS", $5 "REPORT_DATE", $6 "MESSAGE", $7 "REPORTING_STATES", $8 "STATE_MESSAGES", $9 "OVERALL_CONSISTENCY", $10 "ALERTS", $11 "RUN_DATETIME_PARTITION", $12 "RUN_DATETIME"
TA贡献1883条经验 获得超3个赞
我能够使用字典和一些进一步的解析来找到解决方案:
column_names = final_table_data_frame.drop("run_datetime_partition").schema.names
dict = dict(enumerate(column_names, start = 1))
column_strings = (',').join(['$%s "%s"' % (key, value) for (key, value) in dict.items()]).upper()
添加回答
举报