StatsGirl
StatsGirl Is my first tiny steps into file handling and data use.
I wanted to see how csv worked, and how python could read, display and actually use the data it found there. Its really simple stuff but its really teaching me a lot, I get better by doing things, breaking things and eventually fixing things.
I download a 'webstats.csv' file from neocities and drop it into the same folder she is in and she lists the file in easy to read columns and then finds the most hits and displays which day and how many hits
Here is the code:
#StatsGirl V1.02
import csv
# 1. Initialize "Best day" trackers
max_hits = 0
best_day = ""
with open('webstats.csv') as csv_file:
csv_reader =csv.reader(csv_file, delimiter=',')
next(csv_reader)
line_count = 0
for row in csv_reader:
current_hits = int(row[2])
current_date = row[0]
if current_hits > max_hits:
max_hits = current_hits
best_day = current_date
if line_count ==0:
print(f'Column names are {", ".join(row)}')
line_count += 1
else:
print(f'Date {row[0]:20} Hits {row[1]:<10} Views {row[2]:<10} Bandwidth {row[3]:<10}')
line_count += 1
print("=" * 80)
print(f" --- Analysis Complete --- ")
print(f"The most popular day was {best_day} with {max_hits} views.")
print(f' --- Prosessed {line_count} lines ---')
print("=" * 80)