簡體   English   中英

基於其他列中的值的 Pandas 條件計算

[英]Pandas conditional calculation based on values in other column

我需要從這個數據框計算比特幣 (BTC) 和以太幣 (ETH) 價格的 pct_change:

BTC 和 ETH 收盤價數據框

我想使用的公式基本上是:

initial = df['Close'][0]
final = df.iloc[-1]['Close']

df['Performance'] = (100*(df[symbol] - initial)/initial)

問題是,我不知道如何將 BTC 和 ETH 計算分開。 我怎樣才能做到這一點? 我嘗試制作兩個單獨的數據框,一個用於 BTC,一個用於 ETH,然后使用公式,但出現此錯誤:

試圖在 DataFrame 的切片副本上設置一個值。 嘗試使用 .loc[row_indexer,col_indexer] = value 代替

我能做什么呢?

嘗試使用這些行。 閱讀更多相關信息

import pandas as pd

pd.options.mode.chained_assignment = None  # default='warn'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM