Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 selecting customized seasons from monthly time series
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
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':})
df[df.month.isin([3,4,5])]  # selects data for march, april and may
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?

Look at the sample data frame

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Using shift to compute the percent change in a time series new_to_python 6 432 Mar-03-2020, 07:50 PM
Last Post: new_to_python
  Linear Regression on Time Series karlito 5 218 Jan-28-2020, 10:02 AM
Last Post: buran
  IDE for Finance TIME SERIES Data Trader2013 2 171 Jan-19-2020, 04:44 PM
Last Post: danielgoldfarb
  Time Series Production Process Problem Mzarour 0 182 Dec-06-2019, 06:44 PM
Last Post: Mzarour
  Selecting first and last row in python sudhirkaukuntla 2 272 Oct-01-2019, 06:12 AM
Last Post: sudhirkaukuntla
  Keras: Time series classification midarq 0 294 Sep-25-2019, 09:03 AM
Last Post: midarq
  creating new time series based on giving mean, standard deviation and skewness Staph 1 545 Aug-06-2019, 10:41 PM
Last Post: scidam
  create 10 yearly blocks from time series using pandas Staph 1 355 Jul-23-2019, 12:01 PM
Last Post: Malt
  selecting only october to march from monthly data u Staph 1 209 Jul-14-2019, 10:15 AM
Last Post: Larz60+
  [pandas]How to liner fit time series data and get linear fit equation and r square Sri 5 888 Apr-04-2019, 12:00 PM
Last Post: Sri

Forum Jump:

Users browsing this thread: 1 Guest(s)