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
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With