Python Forum
python resample by day and get weekstart data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python resample by day and get weekstart data
#1
I have monthly data. When I apply resampling by day and cubic interpolation, there is a function to find the month end data

import pandas as pd
df=pd.read_excel(input_file, sheet_name='mthly', usecols='A:D', na_values='ND', index_col=0, header=0)
df.index.names = ['Period']
df.index = pd.to_datetime(df.index)

q= pd.Series(df[series], index=df.index)
d = q.resample('D').interpolate(method='cubic')  
m=d[d.index.is_month_end]
Now I want the data for the start of each week, but I can't find such a function. How do I solve this?

INPUT MONTHLY DATA


Period Values
Jan-22 1
Feb-22 3
Mar-22 7
Apr-22 5
May-22 4



After re-sampling by day and with cubic interpolation

Period
2022-01-01 1.000000
2022-01-02 0.884487
2022-01-03 0.785650
2022-01-04 0.703004
2022-01-05 0.636066
2022-01-06 0.584353
2022-01-07 0.547382
2022-01-08 0.524668
2022-01-09 0.515729
2022-01-10 0.520081
2022-01-11 0.537240
2022-01-12 0.566724
2022-01-13 0.608048
and so on

Desired output is Monday of each week

2022-01-03 0.785650
2022-01-10 0.520081
and so on


Thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Resample from monthly to weekly works, but not vice versa JaneTan 0 587 Dec-14-2022, 12:58 AM
Last Post: JaneTan
  Python Resample: How do I keep NaN as NaN? JaneTan 3 2,240 Dec-08-2022, 10:18 PM
Last Post: deanhystad
  resample grouping pr0blem olufemig 1 1,964 Nov-06-2019, 10:45 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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