pandas-loc

.isin() returning a blank dataframe

.isin() returning a blank dataframe Question: My DataFrame: Trying… Nope… Still nope… AND YET… Any idea why I can’t filter this dataframe by a list using isin? I’m expecting it to return one or more rows where the Chord Notes column equals the list [‘C’,’E’,’G’] Asked By: Sir Roland Baggybottom IV || Source Answers: you …

Total answers: 1

Remove date from datatime index in pandas

Remove date from datatime index in pandas Question: I want to remove the date from datetime function in pandas and the following code works just fine. df= pd.read_csv(‘data.csv’) df[‘Value’]= df.Value.astype(float) df[‘Time’] = pd.to_datetime(df[‘Time’]).dt.time df.set_index(‘Time’,inplace=True) But after that when I try to select rows based on the time using .loc function it gives me the following …

Total answers: 2

Pandas – Blanking out values of one column if value of another column has a specific value

Pandas – Blanking out values of one column if value of another column has a specific value Question: I have the following DataFrame: import pandas as pd df = pd.DataFrame({‘Status’: [”,’To Do’, ”,’Completed’, ‘To Do’, ‘In Progress’, ‘Completed’], ‘Date’: [”,’9/1/2022′,”,’12/5/2019′,’8/12/2020′,’4/19/2020′,’12/31/2018′]}) I want to blank out the Date column for those rows where the Status is …

Total answers: 1

Using Pandas df.loc

Using Pandas df.loc Question: 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 …

Total answers: 2

Combine a variable and a string for naming a column in pandas

Combine a variable and a string for naming a column in pandas Question: I have a dataframe with several column which have similar names, something like col_1, col_2, col_3. I am trying to create a for loop to go over the 3 columns and want to use .loc inside the loop to slice the dataframe. …

Total answers: 1

Filter pandas df with .loc[]

Filter pandas df with .loc[] Question: I have one data frame (df) and a list (posList). I managed to "filter" my df with .loc[] thanks to this piece of code : df = df.loc[ (df[‘Pos’] == posList[0]) | (df[‘Pos’] == posList[1]) ] But then I tried to write this instead (just in case I have …

Total answers: 1

Pandas slice using rows with column labels inside iteration gives future warning

Pandas slice using rows with column labels inside iteration gives future warning Question: This code works inside a for loop where ‘i’ is iterating it through the dataframe rows and occasionally this code line is used to reset all the rows preceeding row ‘i’, in column ‘atr_Lts’, so my cummulation calcs work as I require. …

Total answers: 1