如何确定要附加信息的excel工作表的优先级

2024-06-02 15:19:30 发布

您现在位置:Python中文网/ 问答频道 /正文

以下代码是我正在处理的一个较大项目的一个片段:

import os
import pandas as pd 
from pandas import ExcelWriter
from pandas import ExcelFile

under4 = pd.ExcelFile('Under4Systems.xlsx')
over3 = pd.ExcelFile('Over3SystemsModified.xlsx')
SystemCount= len(over3.sheet_names)

#sets each full sheet within the work books = to a unique dictionary syntax- un4full['s1']
un4full = {}
ov3full = {}

for z in range(1, int(SystemCount)+ 1): 
    un4full["s{0}".format(z)]= pd.read_excel(under4, 'System'+ str(z))
    ov3full["s{0}".format(z)]= pd.read_excel(over3, 'System'+ str(z))


#sets the length of each sheet = to a unique dictionary syntax- u4row['r1']
u4row = {}
o3row = {}
for z in range(1, int(SystemCount)+ 1): 
    u4row["r{0}".format(z)] = int(len(un4full["s"+str(z)]))
    o3row["r{0}".format(z)] = int(len(ov3full["s"+str(z)]))
    lowval = min(u4row.values())

print(lowval)

for a in ov3full['s1'].values:
    if a in ov3full['s1'].values and a in ov3full['s2'].values and a in ov3full['s3'].values:
              print(a)

这两个文件在excel文档中具有相同的样式(相同的标题和页数)。我想迭代Over3SystemsModified文件中的每个工作表,并让它将内容移动到另一个文件中

我如何按长度优先排列哪张表?因此,如果系统4(第4页)在文件2中的数量最少,那么让它在文件1中的同一个表/系统上迭代,传输内容,并且由于用户将在这些表中出现多次,我想限制每个用户仅被传输3次到文件2。因此,如果用户在文件1中出现4次,只有3个将被传输到文件2,剩下文件1中的第4个


Tags: 文件inimportformatpandasintpdvalues