I want to select data from my CSV file.
Though I can get a data in which column
"House" == 1 (any single number)
as following, I don't know how to get the data where
"House" in [1, 2, 3, 4, 6, 7, 8, 9, 10, 13, 17, 18, 20, 21, 23, 26, 28, 30, 34, 46, 57, 58, 61, 86, 89, 102, 121, 156].
df = pd.read_csv('../../data/training_dataset_500.csv')
df[df['House']==1]
Pandas isin() method is used to filter data frames. isin() method helps in selecting rows with having a particular(or Multiple) value in a particular column. Parameters: values: iterable, Series, List, Tuple, DataFrame or dictionary to check in the caller Series/Data Frame.
Pandas DataFrame duplicated() Method The duplicated() method returns a Series with True and False values that describe which rows in the DataFrame are duplicated and not. Use the subset parameter to specify if any columns should not be considered when looking for duplicates.
Finding duplicate rows To find duplicates on a specific column, we can simply call duplicated() method on the column. The result is a boolean Series with the value True denoting duplicate. In other words, the value True means the entry is identical to a previous one.
Use the Series.isin()
method to check if a series value is in a list of values. In your case -
df[df['House'].isin([1, 2, 3, 4, 6, 7, 8, 9, 10, 13, 17, 18, 20, 21, 23, 26, 28, 30, 34, 46, 57, 58, 61, 86, 89, 102, 121, 156])]
Example -
In [77]: df
Out[77]:
A B
0 1 5
1 2 6
2 3 7
3 4 8
In [78]: df[df['A'].isin([1,2])]
Out[78]:
A B
0 1 5
1 2 6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With