向快速数据帧添加新列会引发ValueError:值的长度与索引的长度不匹配

问题描述 投票:0回答:1

我了解此追溯

ValueError: Length of values does not match length of index

由于dataframe期间有一个is longer or shorter than the otherdataframeddf.assign(new_col=ts_colddf['ts_col'] = ts_col中的相同操作而引起的事实。

问题是,我看不出长度有何不同-用代码解释:

from dask import dataframe as dd

# Read data
ddf = dd.read_csv(csv_path)
ddf.persist()


# Convert to unixtimestamp to pandas timestamp
ts_col = pd.to_datetime(ddf.ts_unixtime_sec_prec, unit='s', errors='coerce')
ts_col.fillna()

# Check data
> ts_col[0:2]
< DatetimeIndex(['2019-05-23 09:09:56', '2019-05-23 09:09:56'], dtype='datetime64[ns]', freq=None)

# Checking length
> len(ddf.index) 
< 11227296

> len(ts_col)
< 11227296

# Try to assign it to dataframe.
> ddf['ts_col'] = ts_col
< ValueError: Length of values does not match length of index <<< Error
python dask dask-distributed dask-delayed dask-dataframe
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.