因此,我在 postgres 中存储了一个大型(7GB)数据集,我正在尝试将其导入到 Dask 中。我正在尝试 read_sql_table 函数,但不断收到 ArgumentErrors。
我在 postgres 中的信息如下:
- 数据库是“my_database”
- 架构是“公开的”
- 数据表是“表”
- 用户名是“fred”
- 密码是“my_pass”
- postgres 中的索引是“idx”
我正在尝试让这段代码正常工作:
df = dd.read_sql_table('public.table', 'jdbc:postgresql://localhost/my_database?user=fred&password=my_pass', index_col='idx')
我的格式是否错误?
最佳答案
我终于能够通过使用 psycopg2 弄清楚它。答案如下:
df = dd.read_sql_table('table', 'postgresql+psycopg2://postgres:fred@localhost/my_database', index_col = 'idx')
此外,我必须在 postgres 表中创建一个不同的索引。原始索引需要是一个完整的单独列。我在 Postgres 中使用以下行执行此操作:
alter table table add idx serial;
关于python - 使用 Dask 从 postgresql 导入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67694082/