Page hit analysis with a cleaned csv log python

66 Views Asked by At

Below is the code to try and clean my csv log, when i run the code i am getting an error; **

Traceback (most recent call last): File "page_hit_analysis.py", line 12, in line = parser(line)

**

import apache_log_parser
from collections import Counter
from pandas import DataFrame
import seaborn


parser = apache_log_parser.make_parser('%h %l %u %t "%r" %>s')

pages = []
with open('cleaned_log7.csv') as in_f:
    for line in in_f:
        line = parser(line)
        pages.append(line['request_url'])

counts = Counter(pages)

selected_pages = [pair[0] for pair in counts.most_common(5)]
print(selected_pages)

graph_pages = [page for page in pages if page in selected_pages]
data = DataFrame({'pages': graph_pages})
print(data)

plot = seaborn.countplot(data=data, x='pages', order=selected_pages)
plot.get_figure().savefig('pages_plot7.png')

The above code works with the uncleaned log but not with the cleaned one.

0

There are 0 best solutions below