简体   繁体   中英

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 have laid out my proposed steps below but I would appreciate any guidance on how to construct my class using methods and instantiation. 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

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. There are more alternatives out there, check www.python-excel.org .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM