I was trying to convert a csv data to html using Pandas. But i was getting the below error UnicodeEncodeError('ascii', u'', 10305, 10306, 'ordinal not in range(128)')
How to resolve this issue
I was trying to convert a csv data to html using Pandas. But i was getting the below error UnicodeEncodeError('ascii', u'', 10305, 10306, 'ordinal not in range(128)')
How to resolve this issue
Importing the pandas module:
import pandas as pd
I create an example csv-file, "odd_numbers.csv", containing the odd numbers from 1 to 9:
1,3,5,7,9
First convert your CSV file (here "odd_numbers.csv") into a Pandas Dataframe, "df":
filename = "odd_numbers.csv"
df = pd.read_csv(filename, header = None)
Then use Pandas to_html function on your new dataframe, "df", and make sure to set the "classes" argument for this function equal to "utf8":
HTML_file = df.to_html(classes='utf8')
The HTML file, "HTML_file", will then contain the following:
<table border="1" class="dataframe utf8">
<thead>
<tr style="text-align: right;">
<th></th>
<th>0</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>1</td>
<td>3</td>
<td>5</td>
<td>7</td>
<td>9</td>
</tr>
</tbody>
</table>