Pandas reading csv files with partial wildcard
Loop over each file and build a list of DataFrame, then assemble them together using concat.
I'm trying to write a script that imports a file, then does something with the file and outputs the result into another file.
df = pd.read_csv('somefile2018.csv')
The above code works perfectly fine. However, I'd like to avoid hardcoding the file name in the code.
The script will be run in a folder (directory) that contains the script.py and several csv files.
I've tried the following:
somefile_path = glob.glob('somefile*.csv')
df = pd.read_csv(somefile_path)
But I get the following error:
ValueError: Invalid file path or buffer object type: <class 'list'>