top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to increment date by week Iin python. ..

+2 votes
514 views

Starting on any day/date, I would like to create a one year list, by week (start date could be any day of week). Having a numerical week index in front of date, ie 1-52, would be a bonus.
ie, 1. 6/4/2013
2. 6/11/2013
3. 6/18/2013....etc to # 52.

And to save that result to a file. Moving from 2.7 to 3.3

posted Jun 4, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote
 
Best answer

from datetime import date, timedelta

the_date = date(year=2013, month=6, day=4)

print "%d. %s" % (1, the_date)

for n in range(2, 53):
the_date = the_date + timedelta(days=7)
print "%d. %s" % (n, the_date)

answer Jun 4, 2013 by anonymous
0 votes

import datetime
start = datetime.date.today()
for i in range(53):
dt = start + datetime.timedelta(days=7*i)
result = "%i. %s" % (
i+1,
dt.strftime('%m/%d/%Y')
)
do_something_with(result)

answer Jun 4, 2013 by anonymous
Similar Questions
+2 votes

I'm a relative newbie to python, and this NG, but it's certainly growing on me.

One thing I'm missing is the increment/decrement operator from C, ie x++, and its ilk. Likewise x += y.

Is there any way of doing this in Python?

0 votes

I'm working on association analysis on my dataset that consist majorly of categorical features and I'm using Cramers' V and Theils U statistical measures for showcasing the association metrics.

I have 2 questions related to the same :

If there are some missing values in some of the columns in my dataset, how should I handle them while calculation Cramers' V and theils u metrics? Shall I replace the missing value with some dummy value?
Note: I'm using python's python library for the calculation of both the metrics.

dython.nominal.cramers_v(data[field1],data[field2]) and dython.nominal.theils_u(data[field1],data[field2])

If I have a column name like "Task Creation Date" that consists of DateTime values. How can I include this field as part of my association analysis? Does Cramers' V and Theils U consider date values as input ? or some conversion is required?

Any help would be much appreciated.

+2 votes

I have python-django installed on ubuntu installed on top of virtual Box. Also I have apache2 installed in the same way. When i visit the page hoisted by Apache2 from my Windows Host machine it worked.
But When i am doing the same for Django pages it's not opening up in Web browser from Host machine.
In the virtual box I am using bridged adapter and Eth0.

Please Help me to sort out this problem

...