随笔 - 633,  文章 - 0,  评论 - 13,  阅读 - 48万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
复制代码
import pandas as pd
import os

def csv_to_html(csv_file_path, html_file_path):
    """
    将CSV文件转换为HTML文件。

    :param csv_file_path: CSV文件的路径。
    :param html_file_path: 要创建的HTML文件的路径。
    """
    # 读取CSV文件
    df = pd.read_csv(csv_file_path)

    # 将DataFrame转换为HTML格式的字符串
    html_table = df.to_html(classes='table table-striped', index=False)

    # 确保路径存在
    os.makedirs(os.path.dirname(html_file_path), exist_ok=True)

    # 将HTML表格字符串写入文件
    with open(html_file_path, 'w', encoding='utf-8') as html_file:
        html_file.write(html_table)

    print(f"CSV文件已成功转换为HTML文件: {html_file_path}")

# 使用示例
csv_file_path = './bones_properties.csv'  # CSV文件的路径
html_file_path = './bones_properties.html'  # 要创建的HTML文件的路径
csv_to_html(csv_file_path, html_file_path)
复制代码

 

posted on   大话人生  阅读(28)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2022-04-18 操作yaml-5
2022-04-18 fixture固件装饰器做用例的前后置-4
2018-04-18 pycharm(pythoon3)_django2.0_xadmin创建测试用例后台管理系统
点击右上角即可分享
微信分享提示