I create a comparison between two pandas dataframes and print-out the output in terminal, like following:
for key in raw.keys():
if key == 'jao_atc':
comparison[key] = raw[key].reindex(data.hourly_index,
fill_value='----')\
.compare(processed[key], keep_equal=True)
print(comparison['jao_atc'])
The output is:
DEtoDK DKtoDE
self other self other
2021-03-28 23:00:00+00:00 ---- 2500.0 ---- 1900.0
2021-03-29 01:00:00+00:00 2500 2500.0 1900 1890.0
2021-03-29 04:00:00+00:00 2500 2500.0 1890 1900.0
2021-03-29 05:00:00+00:00 2500 2500.0 1900 1860.0
2021-03-29 07:00:00+00:00 2500 2500.0 1860 1870.0
... ... ... ... ...
2021-05-31 19:00:00+00:00 1830 2200.0 2470 2500.0
2021-05-31 20:00:00+00:00 2200 2280.0 2500 2500.0
2021-05-31 21:00:00+00:00 2280 2500.0 2500 2360.0
2021-05-31 22:00:00+00:00 2500 2500.0 2360 2170.0
2021-05-31 23:00:00+00:00 2500 NaN 2170 NaN
[1159 rows x 4 columns]
I would like to generate an image from this output, however I do not want to take screenshot of the terminal, instead I am looking for a function like create_image_of_the_print_function(comparison['jao_atc'])
, which will create an image of the terminal output.
Is this possible? how?
This Export a Pandas dataframe as a table image works for the dataframes. Is there more generic applicable solution for all the outputs?
Expected Result:
image(print(comparison['jao_atc'))
with text-to-image
, since I have to use string dataframe converted to_string()
which removes the nice format of terminal output: