So, I’m making a game project, and I decided, for once, to make a custom class for my pygame window, like so : And, in the gameloop, I decided to make an instance of this class, and to call the method, like so : But when I try to run the main loop, it gives me this error message (that
Issues setting up python testing in VSCODE using pytest
I am trying to use the testing extension in VSCode with the Python extension. I am using pytest as my testing library. My folder structure looks like this: In the test_main.py file I am trying to import the package code, in order to test it: From the command line, in the root directory, PACKAGENAME, I can use…
While iterating over a list, how can I fill the remainder with a number once a condition has been met?
I have an array = [0, 0, 0, 0, 0, 0, 0, 0]. And say I want to fill in the remainder of my array with 1s, once a certain condition has been met. For example, The above produces a: TypeError: can only assign an iterable. How can I change my code to achieve the above? (P.S.: Is it possible
RegEx to exclude a space between country code and phone number itself?
My goal is to create two groups from a full phone number(which is given in a string): First group: +xyz (any three numbers with a plus sign) Second group: following 7 or 8 digits So, my regex is: ((D?[0-9]{3})(D?s?[0-9]{7,8})) The problem I encountered was that if I have, for example +358 55667788, whitespace…
Apply a softmax function on groupby in the same pandas dataframe
I have been looking to apply the following softmax function from https://machinelearningmastery.com/softmax-activation-function-with-python/ I am trying to apply this to a dataframe which is split by groups, and return the probabilites row by row for a group. My dataframe is: In this instance there are two di…
add a suffix when col names are similar
I am merging two dataframes and both of them have a col called “man”. After the join, one col is called “man_x” and the second is called “man_y”. Is it possible to append the table name or any other string instead of x, y when column names are the same? After this, If I add…
Check equality of multiple elements in array
I’m new to Python from Matlab. I want to create a new variable from a subset of an existing numpy array based on equality to some condition specified by a third numpy array, an ID in this case. This works fine for one equality. But if I try to extend it several equalities at once it no longer works: Ide…
Convert a pandas df to defaultdict and look for matching positive and negative numbers
I have a dataframe like this: What i want to do know i convert the df into a defaultdict and look for only the matching matching positive and negative numbers per id so i want my desired dict to look something like this: I try to do this below but i get this error: Any idea how to solve this
How work to with an array of arrays and how initialize multiple arrays in Numpy?
I have to write an ABM (agent-based model) project in Python and I need to initialize 50 agents which will each contain a different set of numbers. I cannot use a matrix of 50 rows because each agent (each row) can have a different quantity of elements so the vector of each agent has not the same length: when…
Multiple boxplots based on conditions
I have a dataframe with two columns. The power column represents the power consumption of the system. And the component_status column divide the data in two, based when the component is OFF or ON. When the values are 153 is when the component is ON and when the values are 150 the component is OFF. The result …