Skip to content

Instantly share code, notes, and snippets.

@sllynn
Created June 15, 2020 15:18
Show Gist options
  • Save sllynn/9eb3e37449a0614806ccafde676f8052 to your computer and use it in GitHub Desktop.
Save sllynn/9eb3e37449a0614806ccafde676f8052 to your computer and use it in GitHub Desktop.
Pandas UDF for converting Excel dates to Spark timestamps
@pandas_udf("timestamp", PandasUDFType.SCALAR)
def from_xltime(x):
import pandas as pd
import datetime as dt
return (pd.TimedeltaIndex(x, unit='d') + dt.datetime(1899,12,30)).to_series()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment