Python Forum
Python Resampling: How do I obtain the value of the last week of the month?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Resampling: How do I obtain the value of the last week of the month?
#1
Hi

I want to resample to obtain all the values of the last week of the month. However, there are some weeks that overlap between 2 months. For Python, it would ignore such weeks if I use the below code:

m0_2 = q0.resample('M').last()
Eg for Jan, the code take "27-Jan-89" as the last week of the month. But in reality, the week "3-Feb-89" also has days of Jan so I want the value 2 instead.
Thank you.

Initial DF:

20-Jan-89 3
27-Jan-89 4
3-Feb-89 2
10-Feb-89 5
17-Feb-89 3
24-Feb-89 5
3-Mar-89 5
10-Mar-89 6
17-Mar-89 4
24-Mar-89 5
31-Mar-89 7
7-Apr-89 6
14-Apr-89 6
21-Apr-89 4
28-Apr-89 7
5-May-89 5
12-May-89 6
19-May-89 5
26-May-89 7
2-Jun-89 7

Output from code:

1989-01-31 4
1989-02-28 5
1989-03-31 7
1989-04-30 7
1989-05-31 7
1989-06-30 7


DESIRED OUTPUT

Jan Feb Mar Apr May
1989 1989 1989 1989 1989

2.00 5.00 7.00 5.00 7.00
Reply


Messages In This Thread
Python Resampling: How do I obtain the value of the last week of the month? - by JaneTan - Dec-09-2022, 05:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  get list of dates in past month, current and upcoming month jacksfrustration 4 601 Feb-03-2024, 06:37 PM
Last Post: deanhystad
  Print first day of the week as string in date format MyerzzD 2 2,060 Sep-29-2021, 06:43 AM
Last Post: MyerzzD
  Appropriate data-structure / design for business-day relations (week/month-wise) sx999 2 2,829 Apr-23-2021, 08:09 AM
Last Post: sx999
  how to obtain header, data, pararms zarize 4 2,415 Sep-30-2019, 08:17 AM
Last Post: zarize
  Learning Python in a month MuhammadNauman 1 1,791 Jul-17-2019, 11:53 AM
Last Post: metulburr
  Split the list and obtain a single value Gururaj 1 2,163 Jul-12-2019, 12:01 AM
Last Post: scidam
  How to obtain the background color of a cell using xlrd? Krszt 1 12,519 Mar-12-2019, 11:23 PM
Last Post: hshivaraj
  How to get all the data for the current month in ms Access using python? aeo03 1 2,332 Nov-07-2018, 08:21 PM
Last Post: micseydel
  Obtain Geometric Information and name from a map-design website fyec 2 2,470 Aug-08-2018, 05:11 AM
Last Post: buran
  isocalendar value converted back to start of week. cspower 1 2,562 May-30-2018, 05:13 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020