-1

I'm stuck with an equivalence of code between R and Python.

Code in R

library(datasets)
data <- airquality
data2 <- data[data$Ozone < 63,]

I download the file of airquality and use pd.read_csv() function for obtain the .csv file into Python. But I don't know how obtain this equivalent line data[data$Ozone < 63,].

M--
  • 25,431
  • 8
  • 61
  • 93
Bvss12
  • 101
  • 5

1 Answers1

1
data2 = data.loc[data["Ozone"] < 63,:]

This should do the trick.

  • data["Ozone"] < 63 returns an index where the condition is verified
  • data.loc[index, :] returns a copy of the dataframe data, for all columns : on the given index
yco
  • 369
  • 2
  • 11