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 0 else 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)" < code></=threshold>

pandas dataframe apply 传入外部参数 args

pandas dataframe apply 传入外部参数 args

Original: https://www.cnblogs.com/TTyb/p/16261374.html
Author: TTyb
Title: pandas dataframe apply 传入外部参数 args

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/9208/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载