How to log a data-frame to an output file
Question:
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?
Answers:
snap_date.head()
returns pandas.core.frame.DataFrame
object:
>>> type(snap_date.head())
pandas.core.frame.DataFrame
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())
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?
snap_date.head()
returns pandas.core.frame.DataFrame
object:
>>> type(snap_date.head())
pandas.core.frame.DataFrame
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())