Python 将函数应用于循环中的列列表并输出数据帧
我有一个设置如下的函数:Python 将函数应用于循环中的列列表并输出数据帧,python,python-3.x,pandas,list,dataframe,Python,Python 3.x,Pandas,List,Dataframe,我有一个设置如下的函数: def function(df, apply_col, static_col): do something return df #calling the function df = function(df, 'col_a', 'st_col') col_list = ['col_a', 'col_b', 'col_c'....'col_n'] for i in list: df = function(df, i, 'st_col') 这个
def function(df, apply_col, static_col):
do something
return df
#calling the function
df = function(df, 'col_a', 'st_col')
col_list = ['col_a', 'col_b', 'col_c'....'col_n']
for i in list:
df = function(df, i, 'st_col')
这个很好用。但是,我想将此函数应用于按名称列出的列。我试过这样的方法:
def function(df, apply_col, static_col):
do something
return df
#calling the function
df = function(df, 'col_a', 'st_col')
col_list = ['col_a', 'col_b', 'col_c'....'col_n']
for i in list:
df = function(df, i, 'st_col')
我得到一个TypeError:“list”对象不可调用
我希望将此函数应用于循环中的dataframe,静态列保持不变,并返回结果dataframe,所有列都应用了此函数。任何想法都很感激 我认为您的问题在于列表中I的
行:
因为列表被定义为python对象,所以它应该为列表中I的行:
修复,谢谢:)这是一个严重的错误,谢谢捕获。现在可以了!