Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

drop rows with certain values pandas

#to drop rows based on certain condition in a column
import pandas as pd

df = df[df['column']!=1]
Comment

pandas drop rows with value in list

import pandas as pd

a = ['2015-01-01' , '2015-02-01']

df = pd.DataFrame(data={'date':['2015-01-01' , '2015-02-01', '2015-03-01' , '2015-04-01', '2015-05-01' , '2015-06-01']})

print(df)
#         date
#0  2015-01-01
#1  2015-02-01
#2  2015-03-01
#3  2015-04-01
#4  2015-05-01
#5  2015-06-01

df = df[~df['date'].isin(a)]

print(df)
#         date
#2  2015-03-01
#3  2015-04-01
#4  2015-05-01
#5  2015-06-01
Comment

pandas drop row from a list of value

df = df[~df.datecolumn.isin(a)]
Comment

drop rows from dataframe based on column value

def filter_rows_by_values(df, col, values):
    return df[~df[col].isin(values)]
Comment

dataframe drop all rows with value

# create a new dataframe CONTAINING ONLY the rows, where the value
# of some_column = some_value
new_df = old_df.loc[old_df['some_column']=='some_value']
# create a new dataframe EXCLUDING the rows, where the value of
# some_column = some_value
new_df = old_df.loc[old_df['some_column']!='some_value']
Comment

PREVIOUS NEXT
Code Example
Python :: python string to datetime 
Python :: global keyword python 
Python :: install nltk in python 
Python :: execute command in python script 
Python :: Print the norm of a vector and a matrix using numpy. 
Python :: set image size mapltotlib pyplot 
Python :: django staff_member_required decorator 
Python :: read excel file spyder 
Python :: how to randomize order of a list python 
Python :: while not equal python 
Python :: ipython on cmd 
Python :: python swap two elements 
Python :: change case python 
Python :: df concat 
Python :: install python packages from inside within python program 
Python :: how to change role permissions in discord.py 
Python :: print value of tensor 
Python :: how to set up a postgress database for your django projecrt 
Python :: How to install XGBoost package in python on Windows 
Python :: how to make images in python 
Python :: euclidean division in python 
Python :: python list abstraction 
Python :: matplotlib draw two histograms on same image 
Python :: save dictionary to file numpy 
Python :: tkinter button command with arguments 
Python :: how to execute python program in ubuntu 
Python :: clearing canvas tkinter 
Python :: case statement in pandas 
Python :: Math Module log() Function in python 
Python :: sparse categorical cross entropy python 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =