清空文件,两行以下的文件
import os
# 要操作的文件路径
file_path = 'example.txt'
# 删除文件
if os.path.exists(file_path):
os.remove(file_path)
# 重新创建文件
with open(file_path, 'w') as file:
file.write('') # 如果需要写入内容,可以在这里写入
拆分文件选择写入
from openpyxl import load_workbook
from openpyxl import Workbook
from openpyxl import styles
from openpyxl.styles import *
import pandas as pd
import string
import re
import os
from openpyxl.comments import Comment
def segmentation_col(df, col_name):
# 按列的值分组
list_type = df[col_name].unique()
df_list = []
for item in list_type:
df_list.append(df[df[col_name] == item])
return df_list
def create_excel(file_path):
# 没有就创建
if os.path.exists(file_path):
print("文件已存在")
print(file_path)
else:
# 创建一个新的 Excel 文件
wb = Workbook()
wb.save(file_path)
if __name__ == '__main__':
file_path1 = './src/冬装客户库存清理.xlsx'
file_path2 = './src/分组数据.xlsx'
# delete_empty_rows_and_columns(file_path1)
create_excel(file_path2)
# 加载工作簿
wb = load_workbook(file_path1)
# 获取sheet页,修改第一个sheet页面为
name1 = wb.sheetnames[0]
ws1 = wb[name1]
ws1.title = "销售明细"
wb.save(file_path1)
# 销售明细
df0 = pd.read_excel(file_path1, sheet_name='销售明细', dtype={"颜色代码": str, '尺码代码':str})
df0 = df0.dropna()
df_list = segmentation_col(df0, "仓库名称")
print(len(df_list))
for i in range(0, len(df_list)):
item = df_list[i]
item = item.reset_index(drop=True)
store_code = ite

1986

被折叠的 条评论
为什么被折叠?



