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 …

Total answers: 2

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 …

Total answers: 1

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 …

Total answers: 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 …

Total answers: 1

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 …

Total answers: 3

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 …

Total answers: 1

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’: …

Total answers: 1

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 = …

Total answers: 2

Speed up for loop iteration

Speed up for loop iteration Question: Can I somehow speed up this simple code in python? That takes 0.221seconds for executing for some_list in some_list_of_lists: i = 1 while i < len(some_list): a = some_list[i-1] b = some_list[i] i += 2 some_list_of_lists ~110 000 items some_list ~10 items Same code in cython takes only 0.004seconds, …

Total answers: 2

Python compare lists in lists with fixed entries

Python compare lists in lists with fixed entries Question: So I have this script, # g f z n a = [(4264, 7, 1526, 0), (4293, 14, 846, 93), (4174, 6, 962, 0), (4256, 12, 121, 0), (4257, 29, 182, 385) ] #list a ca. 200,000 entries # g f z n id b = …

Total answers: 3