My DataFrame line index and column index store x and y values, while the data values are z values, i.e. f(x, y). Let’s take an example: then f(4, 30) is 160. I would like to make a 3D plot of function f. I don’t really mind if it looks like a 3D histogram or a surface plot – both answers
Run function in another thread
So say there are two running codes: script1 and script2. I want script2 to be able to run a function in script1. script1 will be some kind of background process that will run “forever”. The point is to be able to make an API for a background process, E.G. a server. The unclean way to do it would b…
Dynamically created classes with the same name
I’m trying to dynamically create subclasses in Python with type: and here’s what I see in the output: Obviously, this was not my intention. Two questions in that respect: How does Python handles multiple classes with identical names? What is a pythonic way to handle it? Of course, I can look up th…
(Python) tkinter figures (with colorbar) overlap when using slider
The following codes is to plot contours from five (slider: 0 ~ 4) .xlsx files on tkinter. Each file just contains numerical data in the matrix 12X6 such as When running it, I got Now, if I use fig.clf, for example I got The contour disappeared. I also tried from matplotlib.figure import Figure instead of pypl…
Dill doesn’t seem to respect metaclass
I have recently begun working with dill. I have a metaclass, which I use to create a Singleton pattern. Always have one object at any instant. I am using dill to serialise.The problem is once the object is loaded back, it doesn’t respect the Singleton pattern (enforced by metaclass) and __init__ gets ca…
Plot confidence interval of a duration series
I measured the duration of 6000 requests. I got now an Array of 6000 elements. Each element represents the duration of a connection request in milliseconds. [3,2,2,3,4,2,2,4,2,3,3,4,2,4,4,3,3,3,4,3,2,3,5,5,2,4,4,2,2,2,3,5,3,2,2,3,3,3,5,4……..] I want to plot the confidence interval in Python and in…
How do I find the index of an unknown value in python?
So basically I have a list like this – and I don’t know what val is. So how do I get the index of val (3) only knowing that it is not None Answer This one line solution gives you the first value that is not None. This returns the actual value, to get the index, look into this answer
Create a Nested list from a pandas data frame
I am trying to create a kind of nested list from a pandas data frame. I have this data frame: So I want to create a kind of nested list using the above data frame using ‘id1’ column, and ‘Name1’ and ‘Name2’ columns. For example, if we think about the first row, id1 should b…
Splitting a string within a list into a list of lists and further splitting its elements if special character found
I’ve got a list of strings that I split into a list of list on (‘/>’), yet I want to split the elements of that list within further depending on IF it has a certain character (‘/’) in it while maintaining the order that the ‘further elements’ are split in. So for e…
Using If statement with string values in Python
I have a df where column A is either blank or has a string in it. I tried to write the if statement (all columns are strings) below. Basically, if there is something (any value) in df[A], then the new column value will be a concatenation of columns A, B and C. If there is no value in df[A], then