title: For loop json files in Python
body: <p>I have 10 json files called <code>Herald500_2005</code>, <code>Herald500_2006</code>.... <code>Herald500_2015</code>. I am trying to carry the same search of keywordswords in each file. Instead of doing it one by one I would like to be able to do it in a loop. So far I have tried the following code:</p>
  
  <pre><code>for i in range(5,15):
      df = pandas.DataFrame([json.loads(l) for l in open('Herald500_200i.json')])
  # Parse dates and set index
      df.date = pandas.to_datetime(df.date)
      df.set_index('date', inplace=True)
  # match keywords
      matchingbodies = df[df.body.str.contains("|".join(keywords3))&amp;df.body.str.contains("|".join(keywords2))&amp;df.body.str.contains("|".join(keywords1))].body
  # Count by month
      counts = matchingbodies.groupby(lambda x: x.month).agg(len)
  
      print "TH 200i" 
      print counts
  </code></pre>
  
  <p>By running this code I am getting the following error:</p>
  
  <pre><code>&lt;ipython-input-9-76f2d2649df0&gt; in &lt;module&gt;()
        1 for i in range(5,15):
  ----&gt; 2     df = pandas.DataFrame([json.loads(l) for l in open('Herald500_200i.json')])
        3 # Parse dates and set index
        4     df.date = pandas.to_datetime(df.date)
        5     df.set_index('date', inplace=True)
  
  IOError: [Errno 2] No such file or directory: 'Herald500_200i.json'
  </code></pre>
  
  <p>Any idea how to correct the code? </p>
  
  <p>Kind regards</p>