jeudi 5 novembre 2015

Categorize Data by Day of Week Python

Given a list of lists in Python 2.7:

[['OCT 27, 2015',2,4,6,8],['NOV 03, 2015',1,5,9,2],['NOV 05, 2015',2,4,6,8]]

How do you print out the averages of the list in general; then averages based on the day of the week. EG:

2.5, 6.5, 10.5, 9, 1.5, 4.5, 7.5, 5, 2, 4, 6, 8

Where:

1.5, 4.5, 7.5, 5 are the average values produced above since Tuesday occurs twice in this list

2.5, 6.5, 10.5, 9 are the averages of the list in general

Then 2, 4, 6, 8 is the average of Thursday occurrences

I'm pretty sure I can use the zip() function to get all the like values. I'm just not sure about the averages calculated per day of the week (Monday, Tuesday, Wednesday,...)

How might I organize this into a clean looking tabular format with "Averages" and "Monday, Tuesday,.." as other headers

   Averages     Monday      Tuesday      Wednesday   Thursday   Friday  Saturday Sunday
2.5 6.5 10.5 9    0      1.5 4.5 7.5 5       0       2 4 6 8       0       0       0

Should I use an if statement, or switch statement?

Aucun commentaire:

Enregistrer un commentaire