Converting time data into a value for an array
<p>I'm writing a basic simulation for an astronomy application. I have a .csv file which is a list of observations. It has 11 columns where columns 2, 3, 4, 5, are decimal hour, day, month, year respectfully. The rest are names, coordinates etc. Each night, a selection of objects are observed once per night.</p>

<p>Each entry in these columns corresponds to when an observation was made. For example: <code>22.583, 5, 1, 2015</code> is equivalent to 22:35pm on the 5th Jan 2015 (0.583 is 35/60 minutes as a fraction). The whole file is 'resolved' to 5 minute intervals.</p>

<p>I also have written some code that produces data at a given time interval.</p>

<p>What I want is a way to interpret the 4 time and date columns so that I have a timestamp that is a simple value of 'how many 5 minutes since t=0'.</p>

<p>This would result in a single time-date array that reads 0,1,2,3,4... for the first 5 possible observations. It's worth noting here that in the original csv file that the data doesn't occupy every possible 5 minute interval, there are gaps of varying length.</p>

<p>Ultimately I want to be able to have a list of time-date values when each object was observed. </p>

<p>As an example, what I have now is (for columns 1,2,3,4,5 only):</p>

<pre><code>star1, 0.250, 1, 1, 2015
star2, 0.583, 1, 1, 2015
star3, 0.916, 1, 1, 2015
star1, 0.250, 2, 1, 2015
star2, 0.583, 2, 1, 2015
star3, 0.916, 2, 1, 2015...
</code></pre>

<p>Which I'd like to turn into:</p>

<pre><code>t_star1 = [3, 291,...]
t_star2 = [7, 295,...]
t_star3 = [11, 299,...]
</code></pre>

<p>Here I used 00:00 on 1st Jan 2015 as t=0, so 00:05/1/1/2015 is t=1 and so on every 5 minutes. My csv file actually runs for 10 years and has about 70,000 entries.</p>

<p>What makes this complicated (for me) is that in the time column the hours/minutes are expressed in a funny way, and that each month has a different number of days in it. So to find the timestamp of something isn't a simple operation.</p>

<p>Thanks!</p>

<p>Consider using the standard <code>datetime</code> module: <a href="https://docs.python.org/3.5/library/datetime.html" rel="nofollow">https://docs.python.org/3.5/library/datetime.html</a></p>

<pre><code>from datetime import datetime
hourminute = .25
day = 1
month = 1
year = 2015
datetime(year, month, day, int(hourminute//1), round(int((hourminute%1) * 60)))
</code></pre>

<p>Then <code>datetime</code> has a bunch of methods for converting between time repersentations.</p>

python date csv datetime