0

I´m using imgkit to create a pdf with images created from html that comes from a dataframe. I need whole specific rows to be bold [rows: 0 and 7] but haven't achieved it. What am I missing?

html = df.style\
         .set_properties(**{'width': 200, 'background-color': '#eae2d5',
                            'color': 'black', 'font-size': '14px',
                            'text-align': 'left'},
                         subset=['var1'])\
         .set_properties(**{'color': '\033[1m'},  # BOLDING rows 1   
                         subset=['var1'][0])\   # Here is the error.    .
         .set_properties(**{'color': '\033[1m'},  # BOLDING rows 7   
                         subset=['var1'][7])\   # Here is the error.              
         .set_properties(**{'width': 80, 'background-color': '#eae2d5',
                            'color': 'black', 'font-size': '14px',
                            'text-align': 'center'},
                         subset=['var3', 'var4'])\
         .set_table_styles([{'selector': 'thead',
                             'props': [('background-color', '#b2361e'),
                                       ('color', 'white'),
                                       ('font-size', '18px')]}, ])\
         .highlight_null(null_color='white').hide_index().render()


so far it says: "SyntaxError: unexpected character after line continuation character"

Gabra
  • 101
  • 2

1 Answers1

0

This is a bit more of a style question, so feel free to take my answer with a grain of salt.

First, I would suggest looking at the error message in Python for the specific line which the error occurs. That would help immensely, as we might be looking at the wrong thing. For example, as I tried to read back through your code the first time, my eye went to this line:

'color': '\033[1m'

I don't think this would be a valid color, since your backslash here is operating as an escape character on the 0. Furthermore, I'm not sure what the [ would be doing.

Second, the code is hard to read in general, and Python focuses on readability. Would you be willing to restructure the code to help solve the problem? Perhaps something like this?

https://stackoverflow.com/a/4768979/11323304

I hope this answer helps, and welcome to Stack!

zerecees
  • 697
  • 4
  • 13
  • Thanks for your answer. StackOverflow modified my original code, hope it will stay as the original now. ANd yeah, basically I saw online that "\033[1m" was the code for bolding – Gabra Jun 25 '19 at 14:57