Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将函数应用于循环中的列列表并输出数据帧_Python_Python 3.x_Pandas_List_Dataframe - Fatal编程技术网

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的
行:

修复,谢谢:)这是一个严重的错误,谢谢捕获。现在可以了!