0

I am working on a project that I was able to do manually by hand, but am troubled when trying to write it in Python. I'm a new programmer in college.

I have a .txt file that looks like so (for the sake of space I will only paste a bit, but there is 134 rows, not including the Date, Event #, Time, etc.)

Date   Event #  TIME    Victim Name     V R/G   V Age

150101 0685 2:03    Anderson, Kedral      BM         26

150103 0816 5:57    Shines, Kathryn     WF  54

150106 4417 22:06   Norton, Noella      HF  46

150107 4655 23:27   Speidel, Steven     WM  41

150110 1100 8:35    Orozco, Jose        HM  53

140813 2059 14:53   Liu, Kim Chunng     AF  74

I then need to collect the data, analyze it, and determine:

  • The day of the week each homicide occurred on.

  • A count of the number of homicides that occurred on each day of the week.

  • A count of the number of homicides that fall within each hour block of the 24 hour time clock.

  • A percentage of each racial/gender category for the 2015 homicides.

  • A count of the number of homicide victims falling in each age category (0-10,11-20,21-30,31-40,41-50,51-60, etc.)

  • Then take that data and put it in to a series of plots which I have the code for and know how to do.

Here is the help I need:

  1. I need help with taking each "150101" and using Zeller's congruence to determine the date and put them in a list I believe.

  2. I have a very good idea of what I need to do, I just don't know how exactly to go about it

Here is what I have so far:

fd = open("2015HomicideLog.txt",'r')
bd = {}
skipline = fd.readline()
for line in fd: 
    bd.append(line.split()[0]

Here is my code for zellers:

def zeller(day, month, year):
    if month == 1:
        A = 11
        year = year - 1
    elif month == 2:
        A = 12
        year = year - 1
    elif month == 3:
        A = 1
        year = year
    elif month == 4:
        A = 2
        year = year
    elif month == 5:
        A = 3
        year = year
    elif month == 6:
        A = 4
        year = year
    elif month == 7:
        A = 5
        year = year
    elif month == 8:
        A = 6
        year = year
    elif month == 9:
        A = 7
        year = year
    elif month == 10:
        A = 8
        year = year
    elif month == 11:
        A = 9
        year = year
    elif month == 12:
        A = 10
        year = year

    yearlist = list(str(year))
    twodigityear = yearlist[2] + yearlist[3]

    twodigitcentury = yearlist[0] + yearlist[1]

    B = day
    C = int(twodigityear)
    D = int(twodigitcentury)

    W = (13 * int(A) - 1) / 5
    X = int(C) / 4
    Y = int(D) / 4
    Z = int(W) + int(X) + int(Y) + int(B) + int(C) - (2 * int(D))
    R = Z % 7

    if R == 0:
        print("Sunday")
    elif R == 1:
        print("Monday")
    elif R == 2:
        print("Tuesday")
    elif R == 3:
        print("Wednesday")
    elif R == 4:
        print("Thursday")
    elif R == 5:
        print("Friday")
    elif R == 6:
        print("Saturday")
halfer
  • 19,824
  • 17
  • 99
  • 186
  • can't you just use python time management capacities? – Jean-François Fabre Nov 17 '16 at 21:16
  • I have no clue how to use that, I am fairly new to python, I was told I need to use zeller's – The Illusion Nov 17 '16 at 21:19
  • if there is no assignment requirement for implementing zellers algorithm, you could just [check this out](http://stackoverflow.com/questions/9847213/which-day-of-week-given-a-date-python)...it could save you plenty of time.... – Ekkstein Nov 17 '16 at 21:20
  • @Ekkstein I need to use Zeller's, I already have the code for it – The Illusion Nov 17 '16 at 21:25
  • Please do not [request urgency here](http://meta.stackoverflow.com/q/326569), thanks; it is regarded on most volunteer-based help sites as begging or queue-jumping, and is a good downvote attractor. – halfer Nov 17 '16 at 21:37

0 Answers0