Skip to content

Tag: python

PySpark – Combine a list of filtering conditions

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…

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.

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 …

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…