I have a df that looks like this: I want to create a new column named promoted from the columns master_feature, epic, and feature: value of promoted will be : master feature if adjacent master_feature column value is not null. feature if adjacent feature column value is not null ,and likewise for epic something like: how can I achieve this
Tag: numpy
Change certain values in a dataframe column based on conditions on several columns
Let’s take this sample dataframe : I would like to replace the “B” values in Category by “B2” where there is a C or a D in Subcategory. I tried the following but I get the error “The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()” : I know that some similar questions are
Tensorflow dataset from numpy array
I have two numpy Arrays (X, Y) which I want to convert to a tensorflow dataset. According to the documentation it should be possible to run When doing this however I get the error: ValueError: Shapes (15, 1) and (768, 15) are incompatible This would make sense if the shapes of the numpy Arrays would be incompatible to the expected
Why is the result different ,despite the code is exactly the same?
I want to build a function that sums two numpy arrays into a new array if and only if the distinct indices are euqal. That worked as expected. Now I want to define the function, but the ouput is different, despite that the code is exactly the same. I think it has something to do with the iterator, but i
How can you get rolling value count (frequency) with Pandas? (computationally efficient, no loops)
I have a list of values and I want to get their rolling frequency, so something like this: Of course I can do this with a loop but with a lot of data it can be computationally expensive so I’d much rather use a built-in or something vectorized, etc. But unfortunately, from my searching, there doesn’t seem to be a
Python: Plot sin wav with 3 discrete amplitudes
Using the code below I am able to create a sign wave I would like to create a sin wave which changes it’s amplitude at time 4s, and 8s so that the sin wave looks like the image below I know how to create each of the 3 sin waves in that img, but I don’t know how to combine
Transpose specific rows into columns in pandas
I have a dataset that has information like below: I want to convert this piece of data to this form: How can I convert my data frame to this form ?? I am not getting what should I do in this case. Answer Try with
How to make clusters of Pandas data frame?
I am trying to make a cluster of the following pandas data frame and trying to give the names. E.g – “Personal Info” is cluster name and it consist of (PERSON,LOCATION,PHONE_NUMBER,EMAIL_ADDRESS,PASSPORT,SSN, DRIVER_LICENSE) and also addition of there Counts. which will be 460. Clusters: for reference I am providing clusters structure Input data: Output: Answer You can create an inverse dictionary
Vectorize else-if statement function using numpy
I have an array of 3 dimensional vectors vec and I want to find a perpendicular vector res_vec to each of those vectors respectively. Using other methods I got some numerically unstable behaviour so I just check for the smallest component of that vector and set it to zero, while exchanging the two components that are left and negating one
Deploying Machine Learning Models Flask and REST API
Firstly, I am new to machine learning. I am trying to create a REST API which utilizes a Machine Learning Models with flask. The application When the user enters a speed value into a text box and …