我正在学习如何使用 dask.dataframe 模块读取多个 csv 文件,当尝试读取这些文件时,ValueError: cannot convert float NaN to integer
会抛出错误:
我的代码如下:
import pandas as pd
import numpy as np
import dask.dataframe as dd
for year in range(2000, 2005):
idx = pd.date_range(str(year), str(year + 1), freq='d', closed='left')
pd.DataFrame({'A': np.random.randn(len(idx)),
'B': np.random.randint(len(idx))},
index=idx).to_csv('{0}.csv'.format(year), index_label='date')
df = dd.read_csv('*.csv').set_index('date')
df.head()
因此,每年看起来像这样:
date A B
01/01/2000 1.13334261 135
02/01/2000 -1.071303513 135
03/01/2000 0.654942826 135
04/01/2000 0.452817638 135
05/01/2000 -2.400335129 135
06/01/2000 1.47236587 135