Skip to content
Advertisement

catch exception and return empty dataframe

I query a database and save result as a dataframe which I then transform by factorize with pivot_table. This works fine when database query returns data but it throws an error when no data is returned(this is to be expected). How to catch this exception and return empty dataframe?

JavaScript

DataError: No numeric types to aggregate

Advertisement

Answer

JavaScript

Credits to brenbarn who found the error name for dataerror at How can I catch a pandas DataError?

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement