Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

finding the rows in a dataframe where column contains any of these values python

import pandas as pd

data = {'Month': ['January','February','March','April','May','June','July','August','September','October','November','December'],
        'Days in Month': [31,28,31,30,31,30,31,31,30,31,30,31]
        }

df = pd.DataFrame(data, columns = ['Month', 'Days in Month'])

contain_values = df[df['Month'].str.contains('Ju')]
print (contain_values)
Comment

pandas check if any of the values in one column exist in another

df["exists"] = df.drop("target", 1).isin(df["target"]).any(1)
print(df)

    target  A       B       C       exists
0   cat     bridge  cat     brush   True
1   brush   dog     cat     shoe    False
2   bridge  cat     shoe    bridge  True
Comment

PREVIOUS NEXT
Code Example
Python :: pandas description of dataframe renaming column values 
Python :: count how much a number is in an array python 
Python :: django signals post_save not working 
Python :: react-native-dropdown-picker 
Python :: no python application found, check your startup logs for errors 
Python :: load python file in jupyter notebook 
Python :: select rows in python 
Python :: rename files with spaces in a folder python 
Python :: installing private python packages from requirements.txt 
Python :: how to download from url in python 
Python :: pandas invert a boolean Series 
Python :: convert 2d aray into 1d using python 
Python :: python list to dict 
Python :: Creating and writing to a new file 
Python :: python flask windows 
Python :: python input string 
Python :: check status code urllib open 
Python :: bitwise and python image 
Python :: discord.py get id of sent message 
Python :: how to set gpu python 
Python :: flask session auto logout in 5 mins 
Python :: python get nested dictionary keys 
Python :: read cells in csv with python 
Python :: cronometer python 
Python :: pygame examples 
Python :: python get screen size raspberry pi 
Python :: random normal 
Python :: create virtualenv python3 
Python :: register admin django 
Python :: pyqt5 plain text edit get text 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =