I’m wanting to create a list of permutations or cartesian products (not sure which one applies here) where the sum of values in each permutation totals to a provided value. There should be three parameters required for the function. Sample Size: The number of items in each permutation Desired Sum: The t…
Tag: python
Drawing a closed loop with Altair mark_line without repeating data
See this example and this similar question. I also want to draw a closed loop with mark_line in Altair. However, I am currently in the process of streamlining my code to be more data-efficient, which is presenting a wrinkle that I am having trouble with. I have a dataset of x and y data that I plot as a scatt…
Cleaner Alternative to Nested If/Else
I’m mainly focused on an alternative to if/else’s in create_animal. If there is a more professional way to handle this. In this case, it’s a classifier based on a variable number of traits needed to figure out what the animal is. Since humans are the only animals that speak English, that pro…
How to change the default backend in matplotlib from ‘QtAgg’ to ‘Qt5Agg’ in Pycharm?
Qt5Agg is necessary to use the mayavi 3D visualization package. I have installed PyQt5 and mayavi using pip in a separate copied conda environment. The default backend then changes from TkAgg to QtAgg. This is a bit weird because in an earlier installation in a different PC the default changed directly to Qt5…
How to find maximums’ indexes by row with Numpy?
I have np 2d array and want to get indexes of max by row. For example: Maximum by row is [3, 4, 2]. Indexes are [(0,0) (0,3) (1,1) (1,2) (2,4)] I tried smth like this buf = np.apply_along_axis(lambda x: zip(np.where(x == np.max(x))), axis=1, arr=B) or this buf = np.where(B == np.max(B,axis = 1)) But it doesnt…
How to send message in a Discord Thread?
So I need to create and send messages in discord thread. I have been able to create threads but unable to send message in them. I am using Discord.py library (v2.0 supports thread). This is what I am using to create thread. I have no lead on how to send message in it. Thanks. Answer create_thread() returns th…
Sum values of a coulmn in specific rows in a dataframe
I would like to learn how to specify a “subset-sum” in a dataframe My dataframe looks like this: The Data/Time column is the dataframes’ index With I get the total sum of column A. My aim is to sum up a subset of rows only like between 2022-03-18 07:37:51 and 2022-03-18 07:37:55 so that I ge…
Can you iterate through model fields when you overwrite the save() method in django?
I’m calling a custom save method in my model. The save method is designed to produce some values in the model based on the content of a TextField. This content is stored in a dictionary, and is generated correctly. I’m trying to write a for loop to store the values of the dictionary. The keys corr…
Display order of a stacked line chart
I am using stacked line plots that sometimes have 0 values, and the default plot puts the color of the zero line on top of the actual increasing line. Is there any way to swap the zorder of a stacked line plot? Please see the below simple example: pd.DataFrame([[0,1,1],[1,0,2],[1,0,1],[2,0,3]],columns=[“…
I have an error in my code the current error is a TypeError: ‘NoneType’ object is not subscriptable
This is my current code, I get the error The data looks something like this, I just want to add the data from the code, when bought, when sold, into the last 2 columns in the data, then i will plot the data. Thanks In Advance Answer Your MyStrat function does not return anything, so you’re basically try…