TypeError: Datetime subtraction can only be applied to datetime series

TypeError: Datetime subtraction can only be applied to datetime series

我试图用 pyspark.pandas 库替换 pandas,当我尝试这样做时: pdf 是 pyspark.pandas 数据框

pdf["date_diff"] = pdf["date1"] - pdf["date2"] 

我收到以下错误:

File "C:\Users\abc\Anaconda3\envs\test\lib\site-packages\pyspark\pandas\data_type_ops\datetime_ops.py", line 75, in sub
raise TypeError("Datetime subtraction can only be applied to datetime series.")

类型错误:日期时间减法只能应用于日期时间系列。

将列值设置为日期时间值

pdf['date1'] = pd.to_datetime(pdf['date1'])
pdf['date2'] = pd.to_date_time(pdf['date2'])