Convert DateTime to sequential day of the year
<p>I have a dataframe that contains a series of dates, e.g.:</p>

<pre><code>0    2014-06-17
1    2014-05-05
2    2014-01-07
3    2014-06-29
4    2014-03-15
5    2014-06-06
7    2014-01-29
</code></pre>

<p>Now, I need a way to convert these dates to the sequential day of the year, e.g.</p>

<pre><code>0    168
1    125
2    7
3    180
4    74
5    157
7    29
</code></pre>

<p>All the values are within the same year.
The opposite problem has been asked many times - converting the sequential day of the year to a date, but I need to do the opposite. Is there an easy way to do this with Pandas? Thanks!</p>

<p>EDIT: Answered by piRSquared. Thank you!</p>

<p>Yes, I did it. Please refer my below code. </p>

<p><strong><em><a href="http://i.stack.imgur.com/WYI7k.png" rel="nofollow">Screen shot of my RESULT</a></em></strong></p>

<p>Step 1: Make array of String datatype and add dates in string format. </p>

<p>Step 2: Use for loop because you have multiple dates.</p>

<p>Step 3: Convert String to Date format.</p>

<p>Step 4: Conver Date to LocalDate format.</p>

<p>Step 5: Use getDatOfYear() inbuilt function to get sequential day of the year.  </p>

<pre><code>package test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;

public class ShubhamDateClass{
    public static void main(String[] args) {
        SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
        String[] dateForTest = {"17-JUN-2014","05-MAY-2014","07-JAN-2017","20-JUN-2014","15-MAR-2014", "6-JUN-2014", "29-JAN-2014"};
        for(int i=0;i&lt;dateForTest.length;i++){
            try {

                Date date = formatter.parse(dateForTest[i]);
                System.out.print(formatter.format(date)+" --- ");
                LocalDate dateTest = Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate();
                int dayOfYear2 = dateTest.getDayOfYear();
                System.out.println(dayOfYear2);

            } catch (ParseException e) {
                e.printStackTrace();
            }

        }


    }
}
</code></pre>

python pandas