![]() |
selecting customized seasons from monthly time series - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: selecting customized seasons from monthly time series (/thread-19578.html) |
selecting customized seasons from monthly time series - Staph - Jul-05-2019 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 RE: selecting customized seasons from monthly time series - scidam - Jul-05-2019 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 RE: selecting customized seasons from monthly time series - Staph - Jul-14-2019 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 RE: selecting customized seasons from monthly time series - scidam - Jul-14-2019 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:
|