我已經設計了一個資料幀輸出的樣式,并讓它在 Jupyter Notebook 中顯示我想要的方式,但我遇到了問題,找到了將其保存為影像的好方法。我已經嘗試過
作業代碼:
import pandas as pd
import numpy as np
import dataframe_image as dfi
col_name = 'TestColumn'
temp_df = pd.DataFrame({'TestColumn':['A','B','A',np.nan]})
t1 = (temp_df[col_name].fillna("Unknown").value_counts()/len(temp_df)*100).to_frame().reset_index()
t1.rename(columns={'index':' '}, inplace=True)
t1[' '] = t1[' '].astype(str)
style_test = t1.style.bar(subset=[col_name], color='#5e81f2', vmax=100, vmin=0).set_table_attributes('style="font-size: 17px"').set_properties(
**{'color': 'black !important',
'border': '1px black solid !important'}
).set_table_styles([{
'selector': 'th',
'props': [('border', '1px black solid !important')]
}]).set_properties( **{'width': '500px'}).hide_index().set_properties(subset=[" "], **{'text-align': 'left'})
dfi.export(style_test, 'successful_test.png')
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/402297.html
標籤:
