I have 10 json files called Herald500_2005, Herald500_2006.... Herald500_2015. 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:
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))&df.body.str.contains("|".join(keywords2))&df.body.str.contains("|".join(keywords1))].body
# Count by month
counts = matchingbodies.groupby(lambda x: x.month).agg(len)
print "TH 200i"
print counts
By running this code I am getting the following error:
<ipython-input-9-76f2d2649df0> in <module>()
1 for i in range(5,15):
----> 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'
Any idea how to correct the code?
Kind regards