将转换后的日期时间 str 分配回 dask df
我将 dask 数据框字符串日期列转换为 pandas 日期时间,并创建了一个日期时间索引。 行将其分配回源 dask 数据
当我尝试使用ddf.assign(date=date_parsed)
帧时,我收到一个ValueError: Length of Values (1000000) does not match length of index ( 2)
。
我最初认为 create datetimeindex 具有正确的长度,但源只有 2 个 indeces。我尝试将 datetimeindex 转换为 pd.dataframe,它成功转换,但我无法将 pd.df 添加到 daskdf 中。我也尝试将其转换回系列,但仍然无法附加/分配。
我想做的是将 datetimeindex 分配回源 dask df。
从 pd 转换而来的 dask df 示例。所有值都是字符串数据类型。
df=pd.DataFrame({'fname': ['dwayne','peter','dead','wonder'],
'lname': ['rock','pan','pool','boy'],
'entrydate':['31DEC2021', '22JAN2022', NaN, '15DEC2025']})
ddf = dd.from_pandas(df)
我做了什么:(1)解析输入日期值并转换为日期时间。它给了我以下内容:
DatetimeIndex(['2021-12-31', '2022-01-22', 'NaT', '2025-12-15'], dtype='datetime64[ns]', length=4, freq=None)
(2)我使用 drop 函数删除了“entrydate”列。 (3) 当我尝试分配函数时,我收到 ValueError...
I got my dask dataframe string date column converted to a pandas datetime and it created a datetimeindex. When I try assigning it back to the source dask dataframe using
ddf.assign(date=date_parsed)
line, I get a
ValueError: Length of values (1000000) does not match length of index (2)
.
I initially thought the create datetimeindex have the correct length but the source have only 2 indeces. I tried converting the datetimeindex into a pd.dataframe, which successfully converted but I cannot add that pd.df into the daskdf. I also tried converting it back to a series, but still not able to append/assign.
What I would like to do is to assign the datetimeindex back to the source dask df.
sample dask df converted from pd. all values are string datatype.
df=pd.DataFrame({'fname': ['dwayne','peter','dead','wonder'],
'lname': ['rock','pan','pool','boy'],
'entrydate':['31DEC2021', '22JAN2022', NaN, '15DEC2025']})
ddf = dd.from_pandas(df)
what I did: (1) parsed the entrydate values and converted to datetime. it gave me the following:
DatetimeIndex(['2021-12-31', '2022-01-22', 'NaT', '2025-12-15'], dtype='datetime64[ns]', length=4, freq=None)
(2) I dropped the 'entrydate' column using the drop function.
(3) When I tried the assign function, I get the ValueError...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需使用
分配
创建新列。Dask dataframe
支持pandas
API,因此以下内容有效:另请参阅此答案< /a>.
There is no need to create new column using
assign
.Dask dataframe
supportspandas
API, so the following works:See also this answer.