我正在尝试使用一个列表,该列表包含groupby表示法的列名。我的最终目标是遍历多列并运行计算,而不必多次重写同一行。这可能吗?
a_list = list(['','BTC_','ETH_'])
a_variable = ('{}ClosePrice'.format(a_list[0]))
proccessing_data['RSI'] = proccessing_data.groupby('Symbol').**a_variable**.transform(lambda x: talib.RSI(x, timeperiod=14))
这是我当前遇到的错误,因为它认为我想要不存在的列“ a_variable”。
AttributeError: 'DataFrameGroupBy' object has no attribute 'a_variable'
答案 0 :(得分:0)
显然,以下表示法有效:
proccessing_data['RSI'] = proccessing_data.groupby('Symbol')[('{}ClosePrice'.format(a_list[0]))].transform(lambda x: talib.RSI(x, timeperiod=14))