subsetting a Python DataFrame

I’ll assume that Time and Product are columns in a DataFrame, df is an instance of DataFrame, and that other variables are scalar values: For now, you’ll have to reference the DataFrame instance: k1 = df.loc[(df.Product == p_id) & (df.Time >= start_time) & (df.Time < end_time), [‘Time’, ‘Product’]] The parentheses are also necessary, because of … Read more

Return data subset time frames within another timeframes?

You can use the .index* family of functions to get certain months or certain days of the month. See ?index for the full list of functions. For example: library(quantmod) getSymbols(“SPY”) SPY[.indexmon(SPY)==0] # January for all years (note zero-based indexing!) SPY[.indexmday(SPY)==1] # The first of every month SPY[.indexwday(SPY)==1] # All Mondays

Check if list contains any of another list

You could use a nested Any() for this check which is available on any Enumerable: bool hasMatch = myStrings.Any(x => parameters.Any(y => y.source == x)); Faster performing on larger collections would be to project parameters to source and then use Intersect which internally uses a HashSet<T> so instead of O(n^2) for the first approach (the … Read more