Jul-14-2020, 06:20 PM
I get different output if called,
First Option it returns 3 values rather than 2 (duplicate of MEAN(5))
#1
--
ndays = ([5, 8])
meanALL = []
for n in ndays:
meanALL.append(df.rolling(window=n).Price.mean().groupby('Name').head(n).dropna())
print(meanALL)
OUTPUT
[Name
xyz 261.595
Name: Price, dtype: float64]
[Name
xyz 261.595
Name: Price, dtype: float64, Name
xyz 266.723333
Name: Price, dtype: float64]
------------------------------------------------------------------------------------------------
Second Option it returns 1 value (only MEAN(5))rather than 2
#2
==
def funct1(ndays):
SMA = []
for n in ndays:
meanALL.append(df.rolling(window=n).Price.mean().groupby('Name').head(n).dropna())
return meanALL
print(funct1([5, 8]))
OUTPUT
[Name
xyz 261.595
Name: Price, dtype: float64]
First Option it returns 3 values rather than 2 (duplicate of MEAN(5))
#1
--
ndays = ([5, 8])
meanALL = []
for n in ndays:
meanALL.append(df.rolling(window=n).Price.mean().groupby('Name').head(n).dropna())
print(meanALL)
OUTPUT
[Name
xyz 261.595
Name: Price, dtype: float64]
[Name
xyz 261.595
Name: Price, dtype: float64, Name
xyz 266.723333
Name: Price, dtype: float64]
------------------------------------------------------------------------------------------------
Second Option it returns 1 value (only MEAN(5))rather than 2
#2
==
def funct1(ndays):
SMA = []
for n in ndays:
meanALL.append(df.rolling(window=n).Price.mean().groupby('Name').head(n).dropna())
return meanALL
print(funct1([5, 8]))
OUTPUT
[Name
xyz 261.595
Name: Price, dtype: float64]