Reputation: 41
I have folder full with different csv files which I would like to read, I used glob.glob on Windows and my code worked fine. I switched recently to Mac and when I used the same code it return empty list (with Spyder):
Windows code
data = [pd.read_csv(filename) for filename in glob.glob('C:/Data/*.csv')]
Mac code
data = [pd.read_csv(filename) for filename in glob.glob('~/Documents/Data/*.csv')]
Even if I remove the Tilda it return empty list in Mac
Upvotes: 3
Views: 1919
Reputation: 33671
You can use os.path.expanduser
and then pass the resulting path to the glob.glob
:
In [16]: os.path.expanduser('~/Documents/Data/*.csv')
Out[16]: '/Users/soon/Documents/Data/*.csv'
Upvotes: 1