I have a dataset (Pandas dataframe) that looks like this:
Date Open High ... date year month
0 2002-05-23 1.156429 1.242857 ... 2002-05-23 2002 5
1 2002-05-24 1.214286 1.225000 ... 2002-05-24 2002 5
2 2002-05-28 1.213571 1.232143 ... 2002-05-28 2002 5
3 2002-05-29 1.164286 1.164286 ... 2002-05-29 2002 5
4 2002-05-30 1.107857 1.107857 ... 2002-05-30 2002 5
How can I get the first and last observation per week, month, quarter, 6 months, year etc? I would like to get the prices from the dataset and then calculate the return for each respective period.
EDIT:
Your code gives me the following output for df1:
Index first last
2002-05-26 1.15643 1.21429
2002-06-02 1.21357 1.07857
I would like to have:
First date Last date First value Last value
2002-05-26 2005-06-01 1.15643 1.21429
2002-06-02 2002-06-09 1.21357 1.07857