0

I am trying to use pandas.read_csv to read files that contain the date in their names. I used the below code to do the job. The problem is that the files name is not consistent as the number of date change the pattern. I was wondering if there is a way to let the code read the file with parts of the name is the date in front of the file name?

enter image description here

for x in range(0,10):
dat = 20170401+x
dat2 = dat+15
file_name='JS_ALL_V.'+str(dat)+'_'+str(dat2)+'.csvp.gzip'
df = pd.read_csv(file_name,compression='gzip',delimiter='|')
Vipin
  • 4,851
  • 3
  • 35
  • 65
AOJ keygen
  • 103
  • 1
  • 8

2 Answers2

1

An alternative of using glob.glob() (since it seems not working) is os.listdir() as explained in this question in order to have a list containing all the elements (or just the files) in your path.

toom501
  • 324
  • 1
  • 3
  • 15
1

You can use glob library to read file names in unix style

Below is its hello world:

import glob
for name in glob.glob('dir/*'):
    print name
Vipin
  • 4,851
  • 3
  • 35
  • 65