Last active
May 11, 2021 12:29
-
-
Save canimus/d44d8c73754f90d92e4025104e47fe95 to your computer and use it in GitHub Desktop.
Pyspark Cast 100 columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import reduce | |
from operator import methodcaller | |
import pyspark.sql.functions as F | |
_ts = lambda dataFrame, col: methodcaller('withColumn', f'{col}TimeStamp', F.to_timestamp(F.col(col)/1000))(dataFrame) | |
reduce(lambda a,b: _ts(a,b), ['start','stop'], df).select('startTimeStamp', 'stopTimeStamp').show(truncate=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment