Python 如何在同一列中获取星期几和数字

Python 如何在同一列中获取星期几和数字,python,dataframe,apache-spark,pyspark,apache-spark-sql,Python,Dataframe,Apache Spark,Pyspark,Apache Spark Sql,我有以下代码: identified_new = (spark.table(f'nn_team_{country}.fact_table') .filter(f.col('date_key').between(start,end)) .filter(f.col('is_client_plus')==1) .filter(f.col('source')=='tickets')

我有以下代码:

identified_new = (spark.table(f'nn_team_{country}.fact_table')
                  .filter(f.col('date_key').between(start,end))
                  .filter(f.col('is_client_plus')==1)
                  .filter(f.col('source')=='tickets')
                  .filter(f.col('subtype')=='trx')
                  .filter(f.col('is_trx_ok')==1)
                  .join(dim_customers,'customer_id','inner')
                  .withColumn('week', f.date_format(f.date_sub(f.col('date_key'), 4), 'Y-ww'))
                  .withColumn('day', f.date_format(f.date_sub(f.col('date_key'), 4), 'DD-ww'))
                 )

output_new_users = (identified_new
                    .groupby('week','day')
                    .agg(
                      f.countDistinct('customer_id').alias('new_users'),
                      f.countDistinct('ticket_id').alias('total_tickets'),
                      f.count('ticket_id').alias('tickets')
                    )
                   )

display(output_new_users)

实际产量:

week    day         new_users   total_tickets   tickets
2020-51 350-51        31662      34748           34748
2020-51 348-51        50451      55995           55995
2020-51 349-51        49476      55106           55106
2020-51 351-51        23297      25282           25282
2020-50 347-50        40006      43713           43713
2020-50 346-50        41971      46044           46044
2020-50 345-50        51463      57234           57234
我想得到的是同一单元格中的星期几和月份数。参见所需输出:

week    day                new_users    total_tickets   tickets
2020-51 Monday    14th        31662      34748           34748
2020-51 Tuesday   15th        50451      55995           55995
2020-51 Wednesday 16th        49476      55106           55106
2020-51 Thursday  17th        23297      25282           25282
2020-50 Friday    18th        40006      43713           43713
2020-50 Saturday  19th        41971      46044           46044
2020-50 Sunday    20th        51463      57234           57234
有没有办法在pyspark上实现这一点?谢谢

更改此行

.withColumn('day', f.date_format(f.date_sub(f.col('date_key'), 4), 'DD-ww'))

因此,
day
列具有所需的格式


有关日期格式字符串的更多详细信息,请参见。

能否显示
已识别\u new
.withColumn('day', f.date_format(f.date_sub(f.col('date_key'), 4), 'EEEE dd'))