【发布时间】:2021-09-25 07:42:55
【问题描述】:
我创建了两个 pandas 数据帧之间的比较并在终端中打印输出,如下所示:
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'])
输出是:
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]
我想从此输出生成图像,但是我不想截取终端的屏幕截图,而是寻找像create_image_of_the_print_function(comparison['jao_atc']) 这样的函数,它将创建终端输出的图像。
这可能吗?怎么样?
这个Export a Pandas dataframe as a table image 适用于数据框。 是否有更通用的适用于所有输出的解决方案?
预期结果:
image(print(comparison['jao_atc'))
使用text-to-image,因为我必须使用转换为to_string() 的字符串数据帧,这会消除终端输出的良好格式:
【问题讨论】:
-
@รยקคгรђשค 它会起作用,但它仅适用于数据帧。没有更通用的解决方案吗? TY 但是!
标签: python pandas image terminal output