from statistics import mean
import pandas as pd
df = pd.DataFrame(columns=['A', 'B', 'C'])
df["A"] = [1, 2, 3, 4, 4, 5, 6]
df["B"] = ["Feb", "Feb", "Feb", "May", "May", "May", "May"]
df["C"] = [10, 20, 30, 40, 30, 50, 60]
df1 = df.groupby(["A","B"]).agg(mean_err=("C", mean)).reset_index()
df1["threshold"] = df1["A"] * df1["mean_err"]
Instead of the last line of code, how can I do it as in Pyspark .withColumn() ?
This code wont work. I would like to create new column by using output of operation on the fly similarly like we do in Pyspark withColumn method.
Can anybody have any idea how to do this?
