-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: function for truncating (deleting all rows) an existing table #8673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For dropping a table, you can:
If you want to delete all rows (but not drop the table), that is currently not possible with pandas, but I think
But maybe we should think about how we could integrate this in the pandas api. |
Thanks for the quick and detailed response! |
Is it possible to make pandas delete all the rows instead of dropping the table for if_exists='replace'? |
Closing for now as Won't Fix. PRs welcome |
Hi,
I want to truncate (or even drop) an existing table in SQL server. I didn't find any dedicated function in pandas.io.sql. So I tried to create an empty data frame just to call:
This code does drop the table but then generates exception from sqlalchemy as it tries to re-create an empty table. I can catch and ignore it, and the next call to_sql() with if_exists='append' will create the table correctly, but this is pretty ugly.
Another way I tried is to clear all the rows from the original data frame, leaving the columns:
This almost works: it truncates the table but then insert a single record with all fields as NULL...
You can see the full description at http://stackoverflow.com/questions/26205057/how-can-i-truncate-a-table-using-pandas#comment41130846_26205057
The text was updated successfully, but these errors were encountered: