3

I have just started using DuckDB in python jupyter notebook. So far everything has worked great. I can't figure out how to delete records from a dataframe. When I try:

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')

this generates:

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

Any idea what I am doing wrong. I am just beginning to use python and pandas and really like the SQL features of duckdb operating on a dataframe

Thanks in advance for your help.

arshovon
  • 13,270
  • 9
  • 51
  • 69

1 Answers1

1

DuckDB does not alter dataframes. However, You can generate a new dataframe without the tuples you can delete.

e.g.,


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()

Pedro Holanda
  • 261
  • 1
  • 3