I want to filter a DataFrame on multiple values from different columns. I wrote the following code, but it's giving me an error, ERROR: TypeError: non-boolean (BitArray{1}) used in boolean context
.
df[((df.eruption .== "CC2011") && (df.dataset .== "MODIS.NDVI.CDI")), :]
Where eruption
and dataset
are columns in the dataframe
Any ideas what I am doing incorrectly?
Apart from the answer by Sankios there are the following alternatives:
filter(row -> row.eruption == "CC2011" && row.dataset == "MODIS.NDVI.CDI", df)
and (faster but more verbose):
filter([:eruption, :dataset] => (x, y) -> x == "CC2011" && y == "MODIS.NDVI.CDI", df)
and soon (in DataFrames.jl 1.0 release) you will be able to write:
subset(df, :eruption => ByRow(==("CC2011")), :dataset => ByRow(==("MODIS.NDVI.CDI")))
You can simply concatenate the conditions with the &
operator and putting each condition in brackets ()
.
df[ ( df.eruption .== "CC2011" ) .& ( df.dataset .== "MODIS.NDVI.CDI" ), :]
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