Skip to content

Tag: dataframe

pandas countif negative using where()

Below is the code and output, what I’m trying to get is shown in the “exp” column, as you can see the “countif” column just counts 5 columns, but I want it to only count negative values. So for example: index 0, df1[0] should equal 2 What am I doing wrong? Python Output Answer Fi…

Create a new column based on different columns

I have the below dataframe: I want to create a new column based on this conditions: I have many different conditions in the original df but I’m trying to create a way just to add this conditions. I’m working with phyton in jupyter Answer Since the logic here is pretty complicated, I would suggest …

Trying to pass user input in usecols Pandas

I’m trying to ask the user which columns do they want read in the dataframe from a csv file. I’ve been trying the following: But even this gives an error. Any suggestions? I think so I’m not able to understand the lambda function. The error I’m getting is: pandas.errors.EmptyDataError:…

Occurence of a value in many lists

i have a Series Object in pandas with 2 columns, one for the indices and one with lists, I need to find if a value occurs in only one of these lists and return it with the most optimal way. As an example let’s say we have this i need to return 77 because it occurs in only one of