I have the following code:
# Get the min and max dates
minDate, maxDate = df2.select(f.min("MonthlyTransactionDate"), f.max("MonthlyTransactionDate")).first()
d = pd.date_range(start=minDate, end=maxDate, freq='MS')
tmp = pd.Series(d)
df3 = spark.createDataFrame(tmp)
I have checked tmp and a I have a pandas dataframe of a list of dates. I then check df3 but it looks like lit's just an empty list:
++
||
++
||
||
||
||
||
||
||
||
What's happening?
In your case d
is DatetimeIndex
. What you can do is create pandas DataFrame from DatetimeIndex
and then convert Pandas DF to spark DF. PFB Sample code.
import pandas as pd
d = pd.date_range('2018-12-01', '2019-01-02', freq='MS')
p_df = pd.DataFrame(d)
spark.createDataFrame(p_df).show()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments