pandas dataframe apply 传入外部参数 args
# !/usr/bin/python3
import pandas as pd
# 如果x小于threshold就等于1,否则等于0
def juege_threshold(x,threshold):
return 1 if x<=threshold else 0
data_dict={"values":[1,3,5,7,9,11,13,15,17,19]}
data_df=pd.DataFrame(data_dict)
print(data_df)
data_df["values_7"]=data_df["values"].apply(juege_threshold,threshold=7)
data_df["values_10"]=data_df["values"].apply(juege_threshold,threshold=10)
print(data_df)