简体   繁体   中英

Question on pyspark data frame for timestamp

I have a dataframe in which one of the column is a time stamp.

enter image description here

How can i create another data frame from this column in the below format

enter image description here

Can i get some help here please?

Let's say your timestamp column name is time:

from pyspark.sql.functions import * 
df2 = df1.withColumn('year',year('time')).withColumn('quarter',quarter('time')).withColumn('weekOfTheYear',weekofyear('time')).withColumn('dayOfTheWeek', dayofweek('time')).withColumn('dayofmonth',dayofmonth('time'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM