所以我有以下熊猫系列grouped: AmountTicker Unit Date Time FLWS SHARES 2019-01-03 - 20.0 2019-01-13 - 20.0PIH SHARES 2019-01-13 - -10.0 VALUE 2019-01-03 - -25.0*我想重置索引以将“数量”作为多索引和“下拉”删除,但随后分组变为未堆叠,并且仅在系列转换为数据帧之后。我正在尝试遍历组: for ticker, action, date, time in grouped: print(ticker) print(action) print(date) print(time)但我得到以下信息: TypeError: 'float' object is not iterable附加信息:我从以下内容中获得了提到的数据框:orders = pd.DataFrame(OrderedDict([ ('Ticker', tickers), ('Action', actions), ('Unit', units), ('Amount', amounts), ('Date', dates), ('Time', times), ])) df_orders = pd.DataFrame(orders)if not df_orders.empty: df_orders.loc[df_orders['Action'] == 'SELL', 'Amount'] *= -1 grouped = df_orders.groupby(['Ticker', 'Unit', 'Date', 'Time'])['Amount'].apply(np.sum) print(grouped)其中tickers, actions,units等都是列表编辑:我认为最好显示我想要处理获取的数据的逻辑。total = 0for ticker in tickers: for date in dates: if unit=='SHARES': total += some_function(ticker, date) else: total += some_function(ticker, date) 请注意,在这种情况下,股票代码中的每个股票代码都是唯一的。那么你将如何以这种方式迭代分组系列?
添加回答
举报
0/150
提交
取消