1

我正在尝试做一些相当简单的事情,但是要么odo坏了,要么我不明白 datashapes 在这个包的上下文中是如何工作的。

CSV 文件:

email,dob
tony@gmail.com,1982-07-13
blah@haha.com,1997-01-01
...

编码:

from odo import odo
import pandas as pd

df = pd.read_csv("...")
connection_str = "postgresql+psycopg2:// ... "

t = odo('path/to/data.csv', connection_str, dshape='var * {email: string, dob: datetime}')

错误:

AssertionError: datashape must be Record type, got 0 * {email: string, dob: datetime}

如果我也尝试直接从 DataFrame -> Postgres 进入,也会出现同样的错误:

t = odo(df, connection_str, dshape='var * {email: string, dob: datetime}')

其他一些不能解决问题的事情:1)从 CSV 文件中删除标题行,2)更改var为 DataFrame 中的实际行数。

我在这里做错了什么?

4

1 回答 1

1

connection_str有表名吗?当我遇到类似问题但使用 sqlite 数据库时,这为我解决了这个问题。

应该是这样的:

connection_str = "postgresql+psycopg2://your_database_name::data"
t = odo(df, connection_str, dshape='var * {email: string, dob: datetime}')

其中 'connection_str' 中的 'data' 是您的新表名。

也可以看看:

python odo sql AssertionError: datashape must be Record type, got 0 * {...}

https://github.com/blaze/odo/issues/580

于 2017-10-03T23:36:52.327 回答