python
Three Excel files are stored in each folder (9 files in total).
practice
│
├201114
│ ├── 1.xlsx
│ ├── 2.xlsx
│ ├── 3.xlsx
├201115
│ ├── 1.xlsx
│ ├── 2.xlsx
│ └── 3.xlsx
└201116
│ ├── 1.xlsx
│ ├── 2.xlsx
│ └── 3.xlsx
I'm trying to drop that file into a data frame and connect it with concat. In the process, I'm thinking of getting the file name with glob and repeating it with listing.
However, if I put a list in the argument of glob, I can't get the file name. What should I do? Please teach me.
import glob import os import pandas as pd os.chdir ('C:/Users/Practice') x = glob.glob ('*') glob.glob ('*') out: ['201114', '201115', '201116'] for i in x: files = glob.glob ('i/*. Xlsx') # This doesn't work files files out: [] # The list is empty and returned df = pd.concat ((pd.read_excel (f)) for f in files)
- Answer # 1
- Answer # 2
files = glob.glob ('i/*. xlsx')To
files = glob.glob (i +'/*.xlsx')I think it is good to set it to.
[Addition]
This is an example of combining xlsx files under the folder as pandas.DataFrame.
x = glob.glob ('*') df_list = [] for i in x: files = glob.glob (i +'/*.xlsx') for file in files: df_list.append (pd.read_excel (file)) df = pd.concat (df_list)
Related articles
- i want to pass the python path in bash
- python - i want to send a list of yahoo news rankings to line
- python 3x - i want to list the strings as they are
- python 3x - i want to convert to str list float list
- python - i want the block to disappear when the ball hits the block
- ruby - #i want to see a list of posts for that user on the user details page
- python - about 2d list
- python - i want to add an element to a double list
- python - i want to scrape google news, but i can't
- python - i want to move images with pygame
- python - i want to handle webdriverchrome ()
- python - i want to know how to keep outputting to csv
- python - i want to solve this problem
- c # - i want to list add (t) to list of another class
- python - i want to resolve typeerror: expected ptr for argument'% s'in cv2countnonzero
- python - i want to find the mode of a pixel with a pixel value of 1 or more
- python - i want to combine two dfs
- c # - i want to add to list type using reflection
- python - mysterious argument () error when using optuna + lihgtgbm i want to somehow store the best
files = glob.glob ('**/*. Xlsx')