# performance

## Is there a way to make my function run faster?

Is there a way to make my function run faster? Question: I have this function, which task is to find out how many numbers, can be selected from the list in such a way, that the difference between any two selected numbers is not greater than t. How can I make it so that its …

## speeding up a double loop on pandas' date frame

speeding up a double loop on pandas' date frame Question: I want to create a data frame (df_aug15_exp) based on another very large data frame (df_aug15). The idea is that for each element in the original data frame, i calculate the sum of the rows and columns of that element, multiply them together and divide …

## Fastest way to get all first-matched rows given a sequence of column values in Pandas

Fastest way to get all first-matched rows given a sequence of column values in Pandas Question: Say I have a Pandas dataframe with 10 rows and 2 columns. import pandas as pd df = pd.DataFrame({‘col1’: [1,2,4,3,1,3,1,5,1,4], ‘col2’: [.9,.7,.1,.3,.2,.4,.8,.2,.3,.5]}) df col1 col2 0 1 0.9 1 2 0.7 2 4 0.1 3 3 0.3 4 1 …

## Applying mathematical operation between rows of two numpy arrays

Applying mathematical operation between rows of two numpy arrays Question: Let’s assume we have two numpy arrays A (n1xm) and B (n2xm) and I want to apply a certain mathematical operation between the rows of both tables. For example, let’s say that we want to calculate the Euclidean distance between each row of A and …

## performance problem, code works but consider takes long time in long list

performance problem, code works but consider takes long time in long list Question: Why the following code is consider inefficient and how can I improve it? while the code works, in huge n or big a/b it fails to deliver instant results. what have I tired? I sorted initially n,a and b but no change …

## How to improve performance of dataframe slices matching?

How to improve performance of dataframe slices matching? Question: I need to improve the performance of the following dataframe slices matching. What I need to do is find the matching trips between 2 dataframes, according to the sequence column values with order conserved. My 2 dataframes: >>>df1 trips sequence 0 11 a 1 11 d …

## Most efficient way to remove a string pattern of several keys based on a list of patterns and removing duplicate keys

Most efficient way to remove a string pattern of several keys based on a list of patterns and removing duplicate keys Question: The objective is to create a clean dictionary key: values pair removing a pattern contained in a list. i.e pattern_list = [‘_PATTERN1′,’_PATTERN2’] test_dictionary = {‘x_PATTERN1’: ‘1’, ‘y_PATTERN2’: ‘Okay…’} #desired result test_dictionary = {‘x’: …

## Create subList of list, with increased performance

Create subList of list, with increased performance Question: Let’s say we’ve got a few lists as follows: list1 = [‘hi’, ‘hello’, ‘goodbye’, ‘caio’, 1.0] list2 = [‘hi’, ‘bye’, 1.0] list3 = [‘hi’, ‘bye’, ‘hello’, 2.0] I want to get it in this format: newList1 = [[‘hi’, ‘hello’], [‘hello’, ‘goodbye’], [‘goodbye’, ‘caio’], [‘caio’, 1.0]] newList2 = …