一、代码

import pandas as pd
import os

class ExcelColumn(object):
    def __init__(self, path, columns=None, converters=None):
        self.path = path
        self.columns = columns or []
        self.converters = converters
        self.df = self.read()

    def read(self):
        if not os.path.exists(self.path):
            raise BaseException("excel路径错误或不存在")
        df = pd.read_excel(self.path, converters=self.converters)
        return df

    @property
    def is_true(self):
        columns = self.df.columns.tolist()
        if not isinstance(self.columns,list):
            raise BaseException("columns格式错误,必须为list")
        if not self.columns:
            return False
        for i in range(len(self.columns)):
            if columns[i] !=self.columns[i]:
                return False
            if columns[i] not in self.columns:
                return False
        else:
            return True


path = r"********.xlsx"
r=["A", "B", "C", "D", "F"]
ef = ExcelColumn(path,r)
print(ef.is_true)

 

相关文章:

  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-12-28
  • 2021-08-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案