I'm trying to understand why this happens in the data frame
import pandas as pd
import numpy as np
#from pyspark.sql import SparkSession
#spark = SparkSession.builder.getOrCreate()
df = pd.DataFrame({"calories": [400, 200, 220, 70000, 500, 200, 300, 200, 100, 100, 100, 200, 300, 100, 200, 300, 400, 500, 100]})
q_low = df["calories"].quantile(0.01)
q_hi = df["calories"].quantile(0.99)
lb = df.quantile(0.01)
ub = df.quantile(0.99)
#replaces outliers with nan
df_filtered = df[(df < ub) & (df > lb)]
#removes outliers
df_filtered = df[(df["calories"] < q_hi) & (df["calories"] > q_low)]
print(df_filtered)
The first df_filtered will set all outliers to NaN, while the second df_filtered will remove all outliers. What is the functional difference between these two operations? Why does the first one set the outliers to NaN, and the second one just remove them?