小编Ant*_*pin的帖子

使用Python编写指数移动平均值

我想对数据帧的三列进行计算df.为了做到这一点,我想在三列表中运行资产(加密货币)列表的价格,以便在有足够的数据后计算它们的指数移动平均值.

def calculateAllEMA(self,values_array):
    df = pd.DataFrame(values_array, columns=['BTC', 'ETH', 'DASH'])
    column_by_search = ["BTC", "ETH", "DASH"]
    print(df)
    for i,column in enumerate(column_by_search):
        ema=[]
        # over and over for each day that follows day 23 to get the full range of EMA
        for j in range(0, len(column)-24):
            # Add the closing prices for the first 22 days together and divide them by 22.
            EMA_yesterday = column.iloc[1+j:22+j].mean()
            k = float(2)/(22+1)
            # getting the first EMA day by taking the following day’s (day 23) …
Run Code Online (Sandbox Code Playgroud)

python math finance python-3.x pandas

3
推荐指数
2
解决办法
6117
查看次数

如何检查DataFrame是否为空?

我想检查DataFrame是否为空:

    BTC_ewma_24  ETH_ewma_24  DASH_ewma_24
24  4011.235578   334.597119        281.15
25  4011.285662   334.591056        281.15
26  4011.373673   334.603479        281.15
27  4011.453068   334.614686        281.15
28  4011.526571   334.624813        281.15
29  4011.591356   334.633980        281.15
30  4011.650075   334.642288        281.15
31  4011.703366   334.649828        281.15
Run Code Online (Sandbox Code Playgroud)

我试过if(self.mean_exp.bool() == False): 但它回答了我:

ValueError: The truth value of a DataFrame is ambiguous.
Use a.empty, a.bool(), a.item(), a.any() or a.all().
Run Code Online (Sandbox Code Playgroud)

好像它甚至没有注意到我使用过 .bool()

然后我用a.empty它并且它回答了我:

AttributeError: 'list' object has no attribute 'empty'
Run Code Online (Sandbox Code Playgroud)

python dataframe is-empty python-3.x pandas

3
推荐指数
1
解决办法
5833
查看次数

标签 统计

pandas ×2

python ×2

python-3.x ×2

dataframe ×1

finance ×1

is-empty ×1

math ×1