Skip to content
Advertisement

Tag: pandas-loc

Using Pandas df.loc

I have a DataFrame of a csv file which is being read by pandas. What I am attempting to do is use df.loc to add a new column but only insert values into the column when values from another column, called “SKU” end with “-RF” and “-NEW”. The code I was working on is below. It has the csv file

LOC search string with AND condition in Python

I’m trying to use LOC with an AND condition. It works fine with OR conditions, but I can’t get it to work with ANDs when there are duplicate values in a column. This table with no duplicates works as expected: But when you create a data frame with two “granny” entries the double replace AND condition replaces both instances of

Update Pandas df Given String Query

As a result of data introduced by users in the interface I have a string query-like. Now I want to update a column of the df based on those conditions, assigning it a variable Z. I don’t know if it can be done somehow with loc Answer I got the solution by myself: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.eval.html

Advertisement