I am trying to create a new dataframe that can pull rows based on multiple terms across multiple columns. I have a huge excel file (65k row) I am pulling into a df so that I can pull out new priority reports. So as an example, this is what I am using to search for multiple terms across 1 column
Tag: dataframe
How to count all the elements in a column with reference to another column Python
I have the following data frame. Port | Label | OtherColumnsFilledWithData 80 | 1 | 60 | 0 | 40 | 1 | 10 | 0 | 80 | 0 | 60 | 0 | 80 | 1 | I want to create another dataframe that says how many of each ports there are with how many times the label
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
Sort dataframe by multiple columns while ignoring case
I want to sort a dataframe by multiple columns like this: However i found out that python first sorts the uppercase values and then the lowercase. I tried this: but i get this error: If i could, i would turn all columns to lowercase but i want them as they are. Any hints? Answer If check docs – DataFrame.sort_values for
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
Classifiy dataframe row according to string occurence from a list
With the following dataframe: And the following list: What is the most efficient way to summarize the occurrence of each word from the list in each row of the column ‘Sentence’? I’m looking for the following result: Thanks in advance! Answer You can do it using apply function as well:
Replacing NaN values in a DataFrame row with values from other rows based on a (non-unique) column value
I have a DataFrame similar to the following where I have a column with a non-unique value (in this case address) as well as some other columns containing information about it. Some of the addresses appear more than once in the DataFrame and some of those repeated ones are missing information. If a certain row is missing the values, but