refactoring

Refactoring pandas using an iterator via chunksize

Refactoring pandas using an iterator via chunksize Question: I am looking for advice on using a pandas iterator. I performed a parsing operation using Python pandas, the size of the input files (a bioinformatics program called eggNOG) is resulting in ‘RAM bottleneck’ phenomenon. It’s just not processing the file. The obvious solution is to shift …

Total answers: 2

How to refactor double for loop faster in Python?

How to refactor double for loop faster in Python? Question: I have a folder with 20,000 stock files, I need to calculate corelation of each stock with each other. dex is indexes lets say they are 10. So for each index i need to calculate the corelation with each of 20K stocks. current code takes …

Total answers: 1

You should add explicit return at end of a function if function have return value except none

You should add explicit return at end of a function if function have return value except none Question: import collections import numpy as np def is_square_magic(rows_and_cols): """is square magic""" matrix = [[int(num) for num in input().split()] for _ in range(rows_and_cols)] matrix_length = np.array(matrix).size uniqueness_check = len(np.unique(matrix)) ascending_sort = np.unique(matrix) if matrix_length == uniqueness_check and ascending_sort[-1] …

Total answers: 1

Code refactoring, where to instantiate an object

Code refactoring, where to instantiate an object Question: I have two files, i.e order.py and shop.py. And I am instantiating a Network object in both of these files. i.e order.py from network import Network … network = Network() shop.py from network import Network from order import Order … network = Network() order = Order() As …

Total answers: 1

How to extracting long views code block in a smaller method?

How to extracting long views code block in a smaller method? Question: I have a Django application. And I have a long method where a user can upload a file and the content of the file will be shown in textarea. Because of the S.O.L.I.D principle. The code that is responsible for extracting the data …

Total answers: 1

how to combine multiple methods in python?

how to combine multiple methods in python? Question: I have three similarmethods. And I think this can be reduced to one method. So I have this almost identical methods: def calulate_totalAnanas_NorthMidSouth(): sheet_factuur = excelWorkbook[‘Facturen ‘] totalAnanasNorth = sheet_factuur.cell(row=6, column=5).value totalAnanasMid = sheet_factuur.cell(row=7, column=5).value totalAnanasSouth = sheet_factuur.cell(row=8, column=5).value totalAnanasNoMidSou = totalAnanasNorth + totalAnanasMid + totalAnanasSouth print(totalAnanasNoMidSou) …

Total answers: 5

Automatically Update Python source code (imports)

Automatically Update Python source code (imports) Question: We are refactoring our code base. Old: from a.b import foo_method New: from b.d import bar_method Both methods (foo_method() and bar_method()) are the same. It just changed the name an the package. Since above example is just one example of many ways a method can be imported, I …

Total answers: 4

Visual Studio Code (Mac OS) rename symbol doesn't work

Visual Studio Code (Mac OS) rename symbol doesn't work Question: When I right click and try to rename a variable name in Microsoft Visual Studio Code on Mac OS Mojave, it prompts for the new name, I hit enter and nothing happens. I have Python extension and Latex extension installed. Usually there are no errors, …

Total answers: 5