看板 Python 關於我們 聯絡資訊
目前我有一個得出的data如下 [Snapshot(ts=1663150448134000000, code='2330', exchange='TSE', open=478.5, high=482.0, low=476.0, close=481.5, tick_type=<TickType.Sell: 'Sell'>, change_price=-11.5, change_rate=-2.33, change_type=<ChangeType.Down: 'Down'>, average_price=479.2, volume=1, total_volume=9175, amount=481500, total_amount=4396651000, yesterday_volume=16507.0, buy_price=481.5, buy_volume=160.0, sell_price=482.0, sell_volume=213, volume_ratio=0.56), Snapshot(ts=1663150456795000000, code='2317', exchange='TSE', open=107.5, high=108.5, low=107.0, close=108.0, tick_type=<TickType.Sell: 'Sell'>, change_price=-2.0, change_rate=-1.82, change_type=<ChangeType.Down: 'Down'>, average_price=107.67, volume=1, total_volume=9599, amount=108000, total_amount=1033550000, yesterday_volume=32733.0, buy_price=108.0, buy_volume=565.0, sell_price=108.5, sell_volume=3292, volume_ratio=0.29)] 有兩個Snapshot開頭的 把他dataframe後 df = pd.DataFrame(snapshots) 會得出以下結果 https://i.imgur.com/1ehIRa8.jpg
但我是想要得到以下結果 https://i.imgur.com/tNLf1iL.jpg
就是把 = 之前的變成欄位名稱, = 之後的變成值 我看別人colab程式碼是直接 df.ts = pd.to_datetime(df.ts) 但我在vscode上直接複製用會跑出錯誤 AttributeError: 'int' object has no attribute 'lower' 請問該怎麼做呢 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.247.201.78 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1663122817.A.52A.html
lycantrope: 只有複製貼上,想都沒想就上來問喔...上一篇也是 09/14 12:09
lycantrope: 也不解釋一下Snapshot是怎麼產生的 09/14 12:09
lycantrope: 通靈就是df=pd.DataFrame(map(dict,snapshots)) 09/14 12:15
抱歉阿 這是用永豐金API使用Contracts得到的DATA就最一開始所示 大大你的通靈有用 的確這樣就解決了 上一篇我已經解決了 我再去自己解答一下 感謝 ※ 編輯: Pettitte1 (27.247.201.78 臺灣), 09/14/2022 13:38:16