2808 explained code solutions for 75 technologies


python-pandasCheck if dataframe column value is in a set of given values


import pandas as pd

data = pd.DataFrame({
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'Phone Price': [204, 304, 404, 405, 305]
})

filtered = data[data['Phone Price'].isin([204,205,304,305])]ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

.isin(

checks if value is in a given set (list) of values

filtered

will contain filtered dataframe

[204,205,304,305]

list to check if a given column value is in


Usage example

import pandas as pd

data = pd.DataFrame({
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'Phone Price': [204, 304, 404, 405, 305]
})

filtered = data[data['Phone Price'].isin([204,205,304,305])]
print(filtered)
output
  Phone  Phone Price
0   ip5          204
1   ip6          304
4    xi          305