Dask“列分配不支持时间戳”

时间:2018-02-12 02:55:28

标签: python pandas datetime dask

尝试将Dandas日期时间添加到Dask DataFrame,可重现的示例如下:

# library imports
import pandas as pd
from sklearn import datasets
from dask import dataframe as dd 

# Load toy data
iris = datasets.load_iris()
DF = pd.DataFrame(iris.data, columns = iris.feature_names)

# Convert Pands DataFrame to Dask DataFrame
ddf = dd.from_pandas(DF, npartitions = 2)

# Add a date column                                                                     
months_ago = 50
some_date = pd.datetime.today() - pd.DateOffset(months=train_months_back)

# Add state column to DataFrame
DF['date_vintage']= some_date # works fine
ddf['date_vintage']= some_date # TypeError: Column assignment doesn't support type Timestamp
  

TypeError:列分配不支持类型Timestamp

我应该如何将一个pandas datetime作为日期时间(非字符串)列添加到dask数据帧?我已经找到了一些关于将字符串转换为dask日期时间或日期时间索引的资源,但无法使其工作。在此先感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

现在在dask版本> = 0.17.1

中实现
df['timestamp'] = pd.Timestamp(...)