I use Pandas to process and output data for a table that is published in Wordpress
I am adding HTML to format the color of a single column
Starting with a sample Dataframe:
import numpy as np import pandas as pd df = pd.DataFrame({ 'A': ['group1', 'group2', 'group3'], 'B': ['foo', 'foo', 'foo'] })
print df
AB 0 group1 foo 1 group2 foo 2 group3 foo
Then I add the same formatting code to each line as follows:
df['Status'] = '<span style="color: #00CD00">Active</span>' print df AB Status 0 group1 foo <span style="color: #00CD00">Active</span> 1 group2 foo <span style="color: #00CD00">Active</span> 2 group3 foo <span style="color: #00CD00">Active</span>
I export the data to a csv file because I need comma delimiters:
output = r'C:\test\test.csv' df.to_csv(output, index=False)
If I open csv in Excel, it will look the same as above
But if I open it in a text editor (which I need to do to get the delimiters), I find that the column with the format string contains additional double-letter characters, for example:
"<span style=""color: #00CD00"">Active</span>"
- this is without the added double queries - which would be correct:
<span style="color: #00CD00">Active</span>
Does anyone know how I can export this without extra characters?
Any help was appreciated.