网站开发的公司属于什么行业,备案通过后怎么做网站,沈阳营销型网站开发,模板建站哪个平台好文章目录 1、安装虚拟环境#xff08;在特定文件夹内#xff09;2、脚本 split.sh3、运行脚本#xff08;在特定文件夹内#xff09;4、结果 1、安装虚拟环境#xff08;在特定文件夹内#xff09;
brew install python3
xcode-select --install
python3 -m venv my_pan… 文章目录 1、安装虚拟环境在特定文件夹内2、脚本 split.sh3、运行脚本在特定文件夹内4、结果 1、安装虚拟环境在特定文件夹内
brew install python3
xcode-select --install
python3 -m venv my_pandas_venv
source my_pandas_venv/bin/activate
pip install pandas
pip install openpyxl2、脚本 split.sh
#!/bin/bash# 检查 Python3 和 pandas 库是否已安装
if ! command -v python3 /dev/null; thenecho 需要安装 Python3。exit 1
fiif ! python3 -c import pandas /dev/null; thenecho 需要安装 pandas 库对于Python3。exit 1
fi# 输入参数验证
if [ $# -ne 1 ]; thenecho 请提供要拆分的 Excel 文件的路径作为参数。exit 1
fiinput_file$1# 使用 pandas 读取 Excel 文件
python3 EOF
import pandas as pd# 读取 Excel 文件
try:df pd.read_excel($input_file)
except Exception as e:print(读取 Excel 文件时发生错误, str(e))exit(1)# 获取总行数
total_rows len(df)# 计算每个文件应包含的行数向上取整
rows_per_file -(-total_rows // 2)# 拆分并保存到两个文件
file1 df[:rows_per_file]
file2 df[rows_per_file:]
try:file1.to_excel(output1.xlsx, indexFalse)file2.to_excel(output2.xlsx, indexFalse)
except Exception as e:print(保存拆分文件时发生错误, str(e))exit(1)print(拆分完成。)
EOF3、运行脚本在特定文件夹内
chmod x split.sh
source my_pandas_venv/bin/activate
(my_pandas_venv) ➜ excelSplit ./split.sh split.xlsx 4、结果 拆分后的文件