Skip to content
Advertisement

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 First DataFrame.where working different, it replace

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 putting your conditions inside a function,

Python DataFrame Filtering and Sorting at the Same Time

Hi I have a data frame with column as following: ‘founded’ and ‘company name’ What I’m trying to do is filtering the year founded > 0 and then sorting by company name, ascending. I’m looking for a code similar to this But I got this error and at the moment I have this code: Are there any way that I

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: No columns to parse from file Answer You can pass the

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

Advertisement