Python Forum

Full Version: Not correct letter in dataframes (if put in png)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I work in Jupiter.When I put pandas dataframe into html and then into png I have some letter (cyrrilic) printed not correct (unreadable symbol). What to do?


import pandas as pd
import matplotlib.pyplot as plt
import imgkit
import seaborn as sns
from IPython.display import HTML
df = pd.DataFrame({'Страна': ['Kazakhstan', 'Россия', 'Belarus', 'Украина'],
'population': [17.04, 143.5, 9.5, 45.5],
'square': [2724902, 17125191, 207600, 603628] })

#Styles
th_props = [
  ('font-size', '13px'),
  ('width','100px'),
  ('text-align', 'center'),
  ('font-weight', 'bold'),
  ('color', '#000000'),
  ('background-color', '#AFEEEE'),('font-family', 'Courier'),

  ('border','2px')
]
# Set CSS properties for td elements in dataframe  
td_props = [  ('font-size', '13px'), ('text-align', 'center')]
# Set table styles
styles = [
  dict(selector="th", props=th_props),
  dict(selector="td", props=td_props)
  ]

#table
df_styled = df.copy()
df_styled = df.style.set_table_styles(styles)
df_styled
html = df_styled.render()
imgkit.from_string(html,'styled_df.png')
Image("styled_df.png")