Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python将csv转换为html Unicodeer错误_Python_Python 2.7_Pandas - Fatal编程技术网

python将csv转换为html Unicodeer错误

python将csv转换为html Unicodeer错误,python,python-2.7,pandas,Python,Python 2.7,Pandas,我试图使用Pandas将csv数据转换为html。 但是我得到了下面的错误 UnicodeEncodeError('ascii',u',10305,10306,'序号不在范围内(128)') 如何解决此问题导入熊猫模块: import pandas as pd 我创建了一个示例csv文件“odd_numbers.csv”,其中包含从1到9的奇数: 1,3,5,7,9 首先将您的CSV文件(此处为“odd_numbers.CSV”)转换为熊猫数据帧“df”: 然后在新的数据框“df”上使用P

我试图使用Pandas将csv数据转换为html。 但是我得到了下面的错误 UnicodeEncodeError('ascii',u',10305,10306,'序号不在范围内(128)')


如何解决此问题导入熊猫模块:

import pandas as pd
我创建了一个示例csv文件“odd_numbers.csv”,其中包含从1到9的奇数:

1,3,5,7,9 
首先将您的CSV文件(此处为“odd_numbers.CSV”)转换为熊猫数据帧“df”:

然后在新的数据框“df”上使用Pandas to_html函数, 并确保将此函数的“classes”参数设置为“utf8”:

HTML文件“HTML_文件”将包含以下内容:

<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>

0
1.
2.
3.
4.
0
1.
3.
5.
7.
9

请分享您对codeAt df.to_html步骤的输入和输出,我面临“UnicodeEncodeError('ascii',u',10305,10306,'序号不在范围内(128)””的问题。请将Pandas to_html方法中的'classes'参数设置为'utf8'。在上面的示例中:当我试图将HTML数据(df.to_HTML(class='utf8'))推送到一个仍面临相同问题的.HTML文件中时,HTML_file=df.to_HTML(class='utf8')
HTML_file    = df.to_html(classes='utf8') 
<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>