1)I have a doubt that since month_dt is a list how is it calling the method strftime because i think we require an object to call.
below is the given code.thanks in advance.
visitors_per_month = {}
for row in potus:
month_dt = row[2]
month_str = month_dt.strftime("%B, %Y")
if month_str not in visitors_per_month:
visitors_per_month[month_str] = 1
else:
visitors_per_month[month_str] += 1
month_dt wouldn’t be a list. In the code, row is a list from the dataset potus, and so row[2] is then going to be the 3rd element of the list. We happened to convert it into a datetime object on the previous screen. So month_dt is going to be a datetime object, which is why we’re able to use .strftime().
If you want to verify, you can take the first couple of rows and print out the row and month_dt so that you can see what it looks like.
for row in potus[:2]: # just first 2 rows for verification
month_dt = row[2]
print('row:', row)
print('month_dt:', month_dt)