For starters, let me define a sample dataframe and import the sql functions: This returns the following dataframe: Now lets say I have a list of filtering conditions, for example, a list of filtering conditions detailing that columns A and B shall be equal to 1 I can combine these two conditions as follows an…
Tag: python
Remove NaN in a python list using max
In a recent interview I was given the following problem. We have a list l = [NaN, 5, -12, NaN, 9, 0] and we want to replaceNaN with -9 using the max function knowing that max(NaN, -9) = -9. What I have tried is : but the output is still the same list. Can’t figure out how to code this.
Pandas apply labels from df1 to df2 if values are within a range in df1
I have two dataframes, df1 and df2. df1 is a table of labels set between ranges: Where the ID column relates to a higher order grouping. Both df1 and df2 contain shared ID’s and I want to apply the labels from df1 to df2. df2 is a table of regularly sampled data: The desired output would look like this:…
Hyperparameter tunning with wandb – CommError: Sweep user not valid when trying to initial the sweep
I’mt rying to use wandb for hyperparameter tunning as described in this notebook (but using my dataframe and trying to do it on random forest regressor instead). I’m trying to initial the sweep but I get the error: 400 response executing GraphQL. {“errors”:[{“message”:̶…
mixed integer programming optimization
I am trying to understand how gekko and its different types of custom variables work. So I wrote a very simple optimization problem, but it won’t find the optimal solution, at least this is what i think the error message means. The code is a simple set switch combination (braco_gas and braco_eh, both bi…
How to pass variable to base class
Consider the following Python code (Python 3): I have a class Signal comprising all the functions signals of all different kinds should be able to perform. For each kind of signal, I create a new class, where the data is “sampled”, meaning an array with signal data is specified. If I now want to p…
Divide into groups according to the specified attribute
I need to group the data in such a way that if the difference between the adjacent values from column a1 was equal to the same pre-specified value, then they belong to the same group. If the value between two adjacent elements is different, then all subsequent data belong to a different group. For example, I …
Adding different days in a DataFrame with a fixed date
I have a DataFrame with numbers (‘number’) and I wanted to add these numbers to a date. Unfortunately my attempts don’t work and I always get error messages no matter how I try…. This is a code example how I tried it: As an example of the result (YYYY/MM/DD) should come out a column or…
websocket await close vs await wait_closed
I’m using the websockets package on python and I’m opening a connection as a client, but NOT in a block context like this: I’m opening the connection like this: The thing is that I don’t under stand what is the right way to close the connection. The document explains here about await c…
How to append value to the ArrayField in Django with PostgreSQL?
I have created a model with the ArrayField in Django Model. I am using PostgreSQL for the database. I want to create new rows in the database or update the existing rows. But I can not insert or append data to the ArrayField. Model View The time field does not being created or updated with the new value. How …