Let’s say current working directory is C:
I created different directories like this
C:\alpha C:\beta C:\gamma ...
All these directories contains files with similar names (they always have the same endings), for example:
C:\alpha\alpha1_fruits.csv C:\beta\beta2_fruits.csv C:\alpha\alpha4_sweets.csv C:\beta\beta2_sweets.csv ...
I created a function that takes as parameter the name of the directory I want to work on and then performs some analysis.
Now i’d like to get the same type of file regardless of the directory. I’ll make an example to clarify.
I coded a function to analyze fruits composition, some times I want to use it on alpha files some other times on beta files. But it should always pick the ‘.*_fruits.csv’ file.
I don’t know how to this inside pandas.read_csv.
Inside the function it is called like this:
def anSweets(DirectoryName): pd.read_csv('C:\\[common path]'+DirectoryName+'beta2_sweets.csv') ...
What I want to do is to substitute beta2_sweets.csv with some general string like ‘_.*sweets.csv’. So that I can reuse the same function for all the directories.