cannot import name 'package' from 'xbot_robot.magic_activities' (unknown location)
回答
收藏

cannot import name 'package' from 'xbot_robot.magic_activities' (unknown location)

不用去猜
2024-05-11 21:36·浏览量:435
不用去猜
影刀中级开发者
发布于 2024-05-11 21:36435浏览

# 使用提醒:
# 1. xbot包提供软件自动化、数据表格、Excel、日志、AI等功能
# 2. package包提供访问当前应用数据的功能,如获取元素、访问全局变量、获取资源文件等功能
# 3. 当此模块作为流程独立运行时执行main函数
# 4. 可视化流程中可以通过"调用模块"的指令使用此模块

import pandas as pd
import xbot
from xbot import print, sleep
from .import package
from .package import variables as glv

from typing import *

def comparison_of_data(excel1,excel2,foreign_key):
    """
    title: 数据比对
    description: 比对两个Excel文件中的数据,并将不一致的数据保存在问题数据.csv文件中。
    inputs: 
        - excel1 (file): 第一个Excel文件的路径,eg: "path/to/excel1.csv"
        - excel2 (file): 第二个Excel文件的路径,eg: "path/to/excel2.csv"
        - foreign_key (str): 用于匹配数据的外键列名称,eg: "发票编号"
    outputs: 
        - result_file (file): 保存不一致数据的文件路径,eg: "path/to/result.csv"
    """
    # 打开应收账款明细账2023年.csv文件和销售发票2023年.csv文件
    excel1 = pd.read_csv(excel1, encoding='GBK')
    excel2 = pd.read_csv(excel2, encoding='GBK')
    # 获取文件的列名称
    excel1columns = list(excel1.columns)
    excel2columns = list(excel2.columns)
    # 找出应收账款明细账2023年.xls文件和销售发票2023年.xlsx文件相同的列
    common_columns = list(set(excel1columns) & set(excel2columns))
    # 找出发票编号在应收账款明细账2023年.xls文件中的索引位置
    excel1_columns_index = excel1columns.index(foreign_key)
    # 找出发票编号在销售发票2023年.xls文件中的索引位置
    excel2_columns_index = excel2columns.index(foreign_key)
    # 遍历应收账款明细账2023年.xls文件中发票编号这一列
    invoice_row_indexall=[]
    for invoice_value in excel1.iloc[:,excel1_columns_index]:
        # 在销售发票2023年.xls文件中找到与发票编号相同的行的索引位置
        invoice_row_index = excel2.index[excel2[foreign_key] == invoice_value].tolist()[0]
        # 将发票编号相同的行的索引位置添加到invoice_row_indexall列表中
        invoice_row_indexall.append(invoice_row_index)

    excel1_column_indexall = []
    selected_data1 = []
    # 遍历common_columns
    for column1 in common_columns:
        # 找出column在应收账款明细账2023年.csv文件中的列索引保存在ys_column_indexall列表中
        excel1_column_indexall.append(excel1columns.index(column1))
        # 逐行遍历数据集,只选取需要的列
    for index, row in excel1.iterrows():
        # 使用iloc和列索引列表来选取需要的列
        selected_data1.append(row.iloc[excel1_column_indexall].tolist())

    excel2_column_indexall = []
    selected_data2 = []
    # 遍历common_columns
    for column2 in common_columns:
        # 找出column在销售发票2023年.csv文件中的列索引保存在ys_column_indexall列表中
        excel2_column_indexall.append(excel2columns.index(column2))
        # 逐行遍历数据集,只选取需要的列
    for index, row in excel2.iterrows():
        # 使用iloc和列索引列表来选取需要的列
        # 将row.iloc[xs_column_indexall]转换为字符串
        selected_data2.append(row.iloc[excel2_column_indexall].tolist())

    # 比对select_data1和selected_data2
    for i in range(len(selected_data1)):
        # 判断selected_data1[i]和selected_data2[i]是否相等
        if selected_data1[i] == selected_data2[i]:
            print("第", i+1, "行数据相同")
        else:
            # 将不一致的数据保存在问题数据.csv文件中
            with open('问题数据.csv', 'a', encoding='utf-8') as f:
                f.write(str(selected_data1[i]) + ',' + str(selected_data2[i]) + '\n')

                print("第", i+1, "行数据不一致")
    return '问题数据.csv'

收藏
全部回答1
最新
发布回答
回答