gpt4 book ai didi

python - DuckDB 从数据帧错误 : RuntimeError: Binder Error: Can only delete from base table 中删除行

转载 作者:行者123 更新时间:2023-12-05 05:39:44 24 4
gpt4 key购买 nike

我刚开始在 python jupyter notebook 中使用 DuckDB。到目前为止,一切都很好。我不知道如何从数据框中删除记录。当我尝试时:

test_df = pd.DataFrame.from_dict({"i":[1, 2, 3, 4], "j":["one", "two", "three", "four"]})

con = duckdb.connect(database=':memory:')

con.execute('delete FROM test_df where i=4')

这会产生:

RuntimeError: Binder Error: Can only delete from base table!

知道我做错了什么。我刚刚开始使用 python 和 pandas,非常喜欢 duckdb 在数据帧上运行的 SQL 特性

预先感谢您的帮助。

最佳答案

DuckDB 不会改变数据帧。但是,您可以生成一个没有元组的新数据框,您可以删除。

例如,


test_df = pd.DataFrame.from_dict({"i":[1, 2, 3, 4], "j":["one", "two", "three", "four"]})

con = duckdb.connect(database=':memory:')

test_df = con.execute('select * from test_df where i!=4').df()

关于python - DuckDB 从数据帧错误 : RuntimeError: Binder Error: Can only delete from base table 中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72604630/

24 4 0