How to log a data-frame to an output file


I’m starting to use logging to an output file but can’t see how to log the head of a data-frame. Is it possible?

I’ve tried debug (logger.debug("snaptable", snap_date.head()), where snap_table is a data-frame, but I can’t see any output when I interrogate the output file.

Is there a type of logging that can do this?

Asked By: Stacey



snap_date.head() returns pandas.core.frame.DataFrame object:

>>> type(snap_date.head())

You should convert it to str, because logger.debug arguments (msg and *args) must be format string and string arguments. Try pandas.DataFrame.to_string:

logger.debug("Snap_date:n %s", snap_date.head().to_string())
Answered By: Sanjar Adilov
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.