Python Forum
selecting customized seasons from monthly time series
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
selecting customized seasons from monthly time series
#1
I have monthlly time seris data like this

data = [1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12,...]

where 1,2,3 represents values for those months respectively.

I want to create select all the data for [1,2,3,10,11,12,1,2,3,10,11,12,...] [4,5,6,7,8,9,4,5,6,7,8,9,...] and a bit stuck now about how to go about this.

Thanks in advance for help
Reply
#2
Are you using Pandas to store the data? In any case, I would suggest to consider Series.isin method or, if you are working with Numpy, numpy.isin.

So, if your data is presented as a DataFrame df, you code may be the following:

import pandas as pd
df = pd.DataFrame({'month': range(1, 13), 'value': pd.np.random.rand(12)})
df[df.month.isin([3,4,5])]  # selects data for march, april and may
Reply
#3
Hello once again

so after using df[df.month.isin([10,11,12,1,2,3])

I get the results to be 1,2,3,10,11,12 meaning the order is changed. Is there a way to keepp the same order after the selection?

thanks
Reply
#4
Look at the sample data frame

df = pd.DataFrame({'month': range(12, 0,-1), 'value': pd.np.random.rand(12)})
Months countdown from 12 to 1. When we do selection
df[df.month.isin([3,4,5])] 
the order is retained:
Output:
month value 8 5 0.296964 9 4 0.780931 10 3 0.343411
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help: Conversion of Electricity Data into Time Series Data SmallGuy 3 1,156 Oct-04-2023, 03:31 PM
Last Post: deanhystad
  Time Series Production Process Problem Mzarour 1 2,097 Feb-28-2023, 12:25 PM
Last Post: get2sid
  reduce time series based on sum condition amdi40 0 1,078 Apr-06-2022, 09:09 AM
Last Post: amdi40
  How to accumulate volume of time series amdi40 3 2,259 Feb-15-2022, 02:23 PM
Last Post: amdi40
  How to split monthly data smoothly into days? AlekseyPython 1 1,509 Jan-27-2022, 10:56 AM
Last Post: Larz60+
  Recommendations for ML libraries for time-series forecast AndreasPython 0 1,862 Jan-06-2021, 01:03 PM
Last Post: AndreasPython
  Time Series forecating with multiple independent variables Krychol88 1 1,823 Oct-23-2020, 08:11 AM
Last Post: DPaul
  how to handling time series data file with Python? aupres 4 2,924 Aug-10-2020, 12:40 PM
Last Post: MattKahn13
  Changing Time Series from Start to End of Month illmattic 0 1,827 Jul-16-2020, 10:49 AM
Last Post: illmattic
  HELP- DATA FRAME INTO TIME SERIES- BASIC bntayfur 0 1,732 Jul-11-2020, 09:04 PM
Last Post: bntayfur

Forum Jump:

User Panel Messages

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