我找不到这个问题的正确搜索条件,所以如果以前已经问过这个问题,请道歉。python函数,允许您命名列(作为函数参数)
基本上,我想要创建一个python函数,允许您命名列(作为函数参数),您将执行某些类型的分析。
例如见下文。很明显,这段代码不起作用,因为'yearattribute'是在df之后的字面意思。我会感谢您的帮助!
def networkpairs2(df, Year):
"""
An effort to generalize the networkpairs function by allowing you to choose the
organization and actor parameter column names
"""
totaldf = df
yearattribute = '%s' %Year
print yearattribute
yearlist = list(np.unique(df.yearattribute))
print yearlist
return
D'oh。我知道我忘记了一些愚蠢的东西。我忘记了这个索引方法。 – user3314418