Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

confusion in understanding error message when writing to .csv

When trying to write a dataframe to csv I get the following error:

In [197]: schdfarrdf.to_csv(ss, sep=',')

[SpyderKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
  File "C:\Users\mtc20tfq\AppData\Local\Programs\Python\Python311\Lib\site-packages\ipykernel\kernelbase.py", line 409, in dispatch_shell
    await result
  File "C:\Users\mtc20tfq\AppData\Local\Programs\Python\Python311\Lib\site-packages\ipykernel\kernelbase.py", line 798, in inspect_request
    reply_content = self.do_inspect(
                    ^^^^^^^^^^^^^^^^
  File "C:\Users\mtc20tfq\AppData\Local\Programs\Python\Python311\Lib\site-packages\ipykernel\ipkernel.py", line 555, in do_inspect
    bundle = self.shell.object_inspect_mime(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mtc20tfq\AppData\Local\Programs\Python\Python311\Lib\site-packages\IPython\core\interactiveshell.py", line 1838, in object_inspect_mime
    return self.inspector._get_info(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mtc20tfq\AppData\Local\Programs\Python\Python311\Lib\site-packages\IPython\core\oinspect.py", line 738, in _get_info
    info_dict = self.info(obj, oname=oname, info=info, detail_level=detail_level)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mtc20tfq\AppData\Local\Programs\Python\Python311\Lib\site-packages\IPython\core\oinspect.py", line 838, in info
    if info and info.parent and hasattr(info.parent, HOOK_NAME):
  File "C:\Users\mtc20tfq\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\generic.py", line 1466, in __nonzero__
    raise ValueError(
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

the .csv file seems to write correctly, but I dont understand why the error occurs, or what it is!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

That looks like a Spyder/ipython bug. You might be able to work around it by adding a second statement such as 0 here

schdfarrdf.to_csv(ss, sep=','); 0

so the REPL doesn’t try (and fail) to interpret the result of the to_csv call.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading