I am trying to analyse a data set (from a CSV file with 100,000+ rows) which includes the date and time for each occurrence in column 1 (in the format YYYY-MM-DD HH:MM:SS) of the file.
Specifically, I am trying to identify the most popular/ busiest day of the week. Drawing on Python most common element in a list and Convert Date String to Day of Week as well as strftime & strptime documentation the code I have written is:
import csv
import collections
import datetime
popular_day = collections.Counter()
with open('data.csv') as input_file:
for row in csv.reader(input_file, delimiter=','):
popular_day += datetime.datetime.strptime(str([row[1][0:10]]), '%B %d, %Y').strftime('%A')
print ('Most popular day: ' + str(popular_day).most_common(1))
With Sublime Text Editor, this returns the error
File "import.py", line 9 popular_day += datetime.datetime.strptime(str([row[1][0:10]]), '%B %d, %Y').strftime('%A') ^ TabError: inconsistent use of tabs and spaces in indentation
With my beginners knowledge of Python this indentation seems logical. At any rate I have tried different indentations without success and have follow the guidelines here "inconsistent use of tabs and spaces in indentation" (useful if anyone is reading this and just started out with Python).
Do I need to break down line 9 into separate functions - where one converts into days of the week format and the other deals with frequency? I can't understand why this would impact indentation, unless it stems from some other underlying problem.