所以我有以下熊貓系列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
提交
取消