亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Pandas DataFrame:無法迭代分組系列

Pandas DataFrame:無法迭代分組系列

墨色風雨 2021-10-10 19:00:19
所以我有以下熊貓系列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)  請注意,在這種情況下,股票代碼中的每個股票代碼都是唯一的。那么你將如何以這種方式迭代分組系列?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 224 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號