Skip to content

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

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=[&#8220…