Javascript

typescript_运行后生成相应的js脚本设置_python_pandas多sheet页保存

本文主要是介绍typescript_运行后生成相应的js脚本设置_python_pandas多sheet页保存,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、typescript_运行后生成相应的js脚本设置:

 

 

 

 

 

 npm init -y命令生成package.json文件和npm install @types/node命令生成node-modules和package-lock.json文件

 

 ctrl+c对js脚本管用,对ts脚本不管用;

疑问:虽然能ts脚本能运行不报错了,但是标红的怎么去除?——重启webstorm就好了

 

2、python的pandas多sheet页保存:

import pandas as pd
import datetime
import openpyxl
import xlwings

def save_to_several_sheet(read_path_name, sava_path_name):
    """软件版本去掉带有'-'符号后的字符串"""
    df = pd.read_excel(read_path_name, header=0, sheet_name="Sheet1")
    for i, row in df.iterrows():
        print(f"编号{i}")
        if "-" in row["软件版本"]:
            df.loc[i, ["去掉横杠的软件版本"]] = row["软件版本"].split("-")[0]
    # 保存数据
    # 1、一起保存为两个sheet页
    with pd.ExcelWriter(sava_path_name) as writer1:
        df.to_excel(writer1, sheet_name='df1', index=False)
        df.to_excel(writer1, sheet_name='df2', index=False)
    # 2、df1和df2的后面再另取一个sheet页保存
    book = openpyxl.load_workbook(sava_path_name)
    writer2 = pd.ExcelWriter(sava_path_name, engine='openpyxl')
    writer2.book = book
    # 转化为字典的形式
    writer2.sheets= dict((ws.title, ws) for ws in book.worksheets)
    df.to_excel(writer2, sheet_name='df3', index=False)
    writer2.save()
    # 3、df1和df2的前面再另取一个sheet页保存: 没有列名
    wb = xlwings.Book(sava_path_name)
    sht = wb.sheets.add(name='df4', before=None, after=None)
    # df.values() # 不然恵插入df的索引
    sht.range("A1").value = df.values
    wb.save()
    wb.close()
    # 4、excel保存报错字符串保存超限制时用
    now_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%S-%f")
    writer3 = pd.ExcelWriter(f"{sava_path_name}_{now_time}", engine='xlsxwriter', options={'strings_to_urls': False})
    df.to_excel(writer3, sheet_name='df5', index=False, encoding="UTF-8")
    writer3.save()

 

这篇关于typescript_运行后生成相应的js脚本设置_python_pandas多sheet页保存的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!