【发布时间】:2019-10-23 14:21:58
【问题描述】:
我正在尝试处理一个相当大的数据集,该数据集在一次加载时使用 Pandas 无法放入内存,因此我使用的是 Dask。但是,在使用 read_csv 方法时,一旦读取数据集,我很难将唯一 ID 列添加到数据集中。我不断收到错误消息(请参阅代码)。我正在尝试创建一个索引列,以便可以将该新列设置为数据的索引,但错误似乎是告诉我在创建列之前先设置索引。
代码
df = dd.read_csv(r'path\to\file\file.csv') # File does not have a unique ID column, so I have to create one.
df['index_col'] = dd.from_array(np.arange(len(pc_df))) # Trying to add an index column and fill it
# ValueError: Not all divisions are known, can't align partitions. Please use `set_index` to set the index.
更新
使用range(1, len(df) + 1 将错误更改为:TypeError: Column assignment doesn't support type range
【问题讨论】:
标签: python pandas dataframe indexing dask