Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
building class
#2
I can't test the following as I don't have a bunch of xlsx files lying around
if you get errors that you can't figure out, post them
from pathlib import Path
import os


class df_excel:
    def __init__(self, sheetname):
		# set starting path (src code repository)
		os.chdir(os.path.abspath(os.path.dirname(__file__)))
		homepath = Path('.')

		self.filelist = [filename for filename in homepath.iterdir() \
			if filename.is_file() and filename.suffix == '.xlsx']

        self.sheetname = sheetname
		

    def excel_to_df(self):
		for file in self.filelist:
        	self.create_df = pd.read_excel(file, self.sheetname)
			yield self.create_df


def main():
	A = df_excel(r'Database_sheet')
	for df in A.excel_to_df()
		print(df)


if __name__ == '__main__':
	main()
Reply


Messages In This Thread
building class - by zarize - Mar-06-2020, 04:06 PM
RE: building class - by Larz60+ - Mar-07-2020, 12:09 AM
RE: building class - by zarize - Mar-09-2020, 09:09 AM
RE: building class - by Larz60+ - Mar-09-2020, 07:21 PM
RE: building class - by zarize - Mar-10-2020, 08:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Building a class for polygons and triangles in 2-space crosshairpvp 0 1,601 Nov-22-2019, 02:04 AM
Last Post: crosshairpvp
  Building a class for sqlite3 interaction Nuzvee 5 3,379 Jan-29-2019, 06:47 AM
Last Post: Nuzvee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020