Skip to content

Tag: pandas

Pandas convert dummies to a new column

I have a dataframe that discretize the customers into different Q’s, which looks like: What I want to do is adding a new column, Q, to the dataframe which shows which sector this customer is in, so it looks like: The only way I can think about is using for loop but it will give me a mess. Any other

iterrows() , if statement and assigning string to new column

I want to add some data to a dataframe to analyse stock price movements. I want to check, if a row is the narrowst range in 7 bars. Unfortunately I seem to be able to run through the df array and perform a basic check. But I can´t assign a string to a column when the If-Statement fulfilled.Any ideas what´s

Merge Dataframe rows based on the date

I have a dataframe that looks like this, It has the name of the company, the date and the title of a headline that was published regarding that company on that day. There are multiple headlines published on that single day and every single one of those headlines take up a different row even for the same date.…

How to speed up pandas transform function?

I’m trying to speed up or vectorise the following slow code The intent of the code is to remove any values that are beyond the upper standard deviation and replace with NaN. I’ve tried to understand the following article about vectorisation but I can’t manage to apply it How to make your Pan…

Python Upper function

The response I get : The response I expected : What can be the issue here? Answer To get the expected output, consider try this: Your df: to get the dictionary: Block Code: