简体   繁体   English

如何使用 OOP 在 Python3 中创建 Class 以从 Excel 文件加载和读取数据?

[英]How can I create a Class in Python3 using OOP to load and read data from an Excel file?

I am trying to create a Class called 'Settings' that can load an excel file, and create a dictionary called 'data' that returns the data from the individual sheets ('the key') of my excel file as a dataframe (the 'value'). I am trying to create a Class called 'Settings' that can load an excel file, and create a dictionary called 'data' that returns the data from the individual sheets ('the key') of my excel file as a dataframe (the '价值')。 I have laid out my proposed steps below but I would appreciate any guidance on how to construct my class using methods and instantiation.我已经在下面列出了我建议的步骤,但我希望能提供有关如何使用方法和实例化构造我的 class 的任何指导。 Thank you谢谢


import pandas as pd

class Settings():
    
#METHOD TO LOAD AN EXCEL FILE
    def load(self):
        self.load = load

#METHOD TO RETURN THE DATA FROM THE LOADED EXCEL INTO DICTIONARIES    
    def data(self):
        self.data = data 

#METHOD TO FILTER SOME OF THE DATA
    def filter_data(self):
        self.filter_data = filter_data

I am also unsure of how to build in the built-in Python operator pd.read_excel into my class or one of the methods我也不确定如何将内置 Python 运算符pd.read_excel到我的 class 或其中一种方法中

You might want to look into openpyxl (reads Excel 2010 xlsx/xlsm) or xlrd (reads historical xls format) to read your Excel files with Python.您可能想查看openpyxl (读取 Excel 2010 xlsx/xlsm)或xlrd (读取历史 xls 格式)以使用 ZA7F5F35426B5674117323 读取 Excel 文件。 There are more alternatives out there, check www.python-excel.org .还有更多选择,请查看www.python-excel.org

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我需要将数据从文件加载到我的 python3 程序 - I need to load data to my python3 program from a file 如何使用 python 中的 OOP 从文本文件创建排行榜? - How to create a leaderboard from a text file using OOP in python? 如何使用 python 读取 excel 文件? - How can I read an excel file with python? 使用 PYTHON 读取 JSON 文件并使用该数据创建一个 excel 文件 - Read JSON file using PYTHON and create an excel file with that data 如何通过使用 tkinter Python 从 excel 文件导入数据来创建具有动态列宽的表? - How should I create a table with dynamic column width by importing data from an excel file using tkinter Python? 从一个文件中读取字典并使用 python 从熊猫创建一个 excel(数据框)l - read dictionaries from one file and create an excel (data frame)l from panda using python 从excel文件python3读取汉字 - read Chinese character from excel file python3 如何从另一个 Python3 文件运行整个 Python3 文件? - How can I run an entire Python3 file from another Python3 file? 如何使用python tkinter将数据附加到Excel文件中 - How can I append data in a excel file using python tkinter Python:如何从 AWS S3 读取和加载 excel 文件? - Python: How to read and load an excel file from AWS S3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM