【Python 实战基础】Pandas如何将表格的前几行生成html

目录

一、实战场景

二、主要知识点

文件读写

基础语法

Pandas

numpy

三、菜鸟实战

1、创建 python 文件

2、运行结果 


一、实战场景

实战场景:Pandas如何将表格的前几行生成html

二、主要知识点

  • 文件读写

  • 基础语法

  • Pandas

  • numpy

三、菜鸟实战

马上安排!

1、创建 python 文件

import numpy as np
import pandas as pd

np.random.seed(66)
s1 = pd.Series(np.random.rand(20))
s2 = pd.Series(np.random.randn(20))

df = pd.concat([s1, s2], axis=1)
df.columns = ['col1', 'col2']

# df.head 取前5行

print(df.head(5).to_html())

2、运行结果 

<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;"> 
      <th></th>
      <th>col1</th>
      <th>col2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.154288</td>
      <td>-0.180981</td>
    </tr>
    <tr>
      <th>1</th>
      <td>0.133700</td>
      <td>-0.056043</td>
    </tr>
    <tr>
      <th>2</th>
      <td>0.362685</td>
      <td>-0.185062</td>
    </tr>
    <tr>
      <th>3</th>
      <td>0.679109</td>
      <td>-0.610935</td>
    </tr>
    <tr>
      <th>4</th>
      <td>0.194450</td>
      <td>-0.048804</td>
    </tr>
  </tbody>
</table>

 菜鸟实战,持续学习!  

猜你喜欢

转载自blog.csdn.net/qq_39816613/article/details/126226763