improve csv_export methods handling of multiple data types
The csv_export method lacks error handling, and has a very peculiar way of handling indexes... Please propose an improved implementation.
See the following gpt dialog for reference: https://chat.openai.com/share/c8b9fae8-4002-4baf-a14f-9ac544492af6