![](/img/trans.png)
[英]Pandas DataFrame apply function to multiple columns and output multiple columns
[英]Apply function to a list of columns in a loop and output dataframe
我有一个 function 设置如下:
def function(df, apply_col, static_col):
do something
return df
#calling the function
df = function(df, 'col_a', 'st_col')
这工作正常。 但是,我想将此 function 按名称应用于列列表。 我试过这样的事情:
col_list = ['col_a', 'col_b', 'col_c'....'col_n']
for i in list:
df = function(df, i, 'st_col')
我得到一个TypeError: 'list' object is not callable
I would like to apply this function to a dataframe in a loop with the static column staying the same and returning a resulting dataframe with all the columns having the function applied to them. 任何想法表示赞赏!
我认为您的问题在于for i in list:
由于列表被定义为 python object 它应该for i in col_list:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.