Skip to content

02

Monotonicity

Decreasing

df["Reading"] = (
  df
  .sort_values("Time_Point", ascending=True) # this is the time column, so always ascending
  .groupby("Temperature")
  ["Reading"]
  .cummin()
)
# or 
df_train["Reading_Time_Point_Cummin"] = (
  df_train
  .sort_values("Time_Point", ascending=True) # this is the time column, so always ascending
  .groupby("Temperature")
  ["Reading"]
  .cummin()
)
df_train = df_train.query("Reading <= Reading_Time_Point_Cummin")

Increasing

df["Reading"] = (
  df
  .sort_values("Time_Point", ascending=True) # this is the time column, so always ascending
  .groupby("Temperature")
  ["Reading"]
  .cummax()
)

df_train["Reading_Time_Point_Cummax"] = (
  df_train
  .sort_values("Time_Point", ascending=True) # this is the time column, so always ascending
  .groupby("Temperature")
  ["Reading"]
  .cummax()
)
df_train = df_train.query("Reading >= Reading_Time_Point_Cummin")

Sampling

# if n=frac, then percentage of dataset
df.sample(
  0.10
)

# if n=int, then count of dataset
df.sample(
  1_000
)

# sampling with prob weights
df.sample(
  1_000,
  weights = "Weight_Column"
)

Multi-Index

df.columns = list(map('_'.join, df.columns.values))
df = df.reset_index()

ObjectName

class Class:
  pass

model = Class()
model_name = type(model).__name__
Last Updated: 2024-05-14 ; Contributors: AhmedThahir

Comments