vala-component-oops-stat.xi.../scripts/generate_excel.py

35 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pandas as pd
import numpy as np
import sys
# 兼容numpy版本
try:
np._get_promotion_state = lambda *args, **kwargs: 0
except:
pass
def generate_excel(l1_csv_path, l2_csv_path, output_path):
"""
生成包含L1和L2两个sheet的Excel报表
:param l1_csv_path: L1等级统计结果CSV路径
:param l2_csv_path: L2等级统计结果CSV路径
:param output_path: 输出Excel文件路径
"""
# 读取CSV文件
df_l1 = pd.read_csv(l1_csv_path)
df_l2 = pd.read_csv(l2_csv_path)
# 创建Excel文件
with pd.ExcelWriter(output_path) as writer:
df_l1.to_excel(writer, sheet_name='L1等级组件', index=False)
df_l2.to_excel(writer, sheet_name='L2等级组件', index=False)
print(f"Excel报表生成成功{output_path}")
if __name__ == "__main__":
if len(sys.argv) != 4:
print("用法python generate_excel.py <l1_csv路径> <l2_csv路径> <输出Excel路径>")
sys.exit(1)
generate_excel(sys.argv[1], sys.argv[2], sys.argv[3])