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
Tag: pandas-loc
Problem: Pandas – Slicing a datetime64[ns] column returns a list of 19-digit integers
I am trying to convert a column of dates in a dataframe to a list, but something is happening when I slice it that turns the dates into 19-digit integers. This is the original df along with the column dtypes: This is the function that turns a dataframe column into a list: This is what is printed after the column
How to look for specific values and return an index in a dataframe?
I have a DataFrame that looks like this: So I have a pair of u and v values (the last two columns). So what I want to ask is, if for example I have a value of u = 279 and a value of v = -108, my output would be Index = 2, is there a way to do
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
Using .loc accessor
I’m trying to use .loc to find out sex of the youngest person here in the chart. The following did not work: Answer You can achieve it like this:
Drop rows from dataframe where problematic values are in separate list
I have a list of problematic rows where there is a unique identifier, all of which I want to remove from a dataframe. I’ve tried to use loc to index them, as follows: where df is 5063 row x 28 cols and toDel[‘GUID’] is a list of GUIDs that I want to remove from the df. I expected this to
Function that takes n rows as input and returns column names if sum in column equals n
I have a large DataFrame that structures as follows: I am trying to build a function that takes in n row names as arguments sums up the values in all columns and returns me the column names if the sum of those columns equals n. For instance, using label1, label2 and label3 as inputs I would like to obtain the