I have a couple of excel sheets (using pd.read_excel
) under a directory and would like to read them as a pandas and add them to a list. so my list should end up having multiple dataframe in it. How can I do that?
Asked
Active
Viewed 9,455 times
0

HHH
- 6,085
- 20
- 92
- 164
-
What code do you have so far? You could just get your current directory, look for excel file, read them to df, put them in list. – MyNameIsCaleb Apr 17 '19 at 15:50
-
11. Please follow the guide for good questions -> where is your code what have you tried so far what error did you encounter – Marvin Taschenberger Apr 17 '19 at 15:51
-
2. then we might help you better. 3, take a look into `pathlib` and `Path` and it's `glob` method and how `list comprehension` works – Marvin Taschenberger Apr 17 '19 at 15:51
-
Try this answer. https://stackoverflow.com/questions/20908018/import-multiple-excel-files-into-python-pandas-and-concatenate-them-into-one-dat – run-out Apr 17 '19 at 16:01
-
duplicate of https://stackoverflow.com/questions/20906474/import-multiple-csv-files-into-pandas-and-concatenate-into-one-dataframe – VnC Apr 18 '19 at 17:28
1 Answers
0
My method for this:
data = os.listdir('data')
df = pd.DataFrame()
for file in data:
path = 'data' + '/' + file
temp = pd.read_excel(path)
df = df.append(temp, ignore_index = True)

keramat
- 4,328
- 6
- 25
- 38