小编joh*_*ohn的帖子

calculate Exponential Moving Average with pandas

I try to calculate ema with pandas but the result is not good. I try 2 techniques to calculate :

The first technique is the panda's function ewn:

window = 100
c = 2 / float(window + 1)
df['100ema'] = df['close'].ewm(com=c).mean()
Run Code Online (Sandbox Code Playgroud)

But the last result of this function gives. 2695.4 but the real result is 2656.2

The second technique is

window = 100
c = 2 / float(window + 1)
df['100sma'] = df['close'].rolling(window).mean()
df['100ema'] = (c * df['close']) + …
Run Code Online (Sandbox Code Playgroud)

python pandas

7
推荐指数
1
解决办法
6440
查看次数

Laravel口才得到的所有,如果变量为空

我有一个模型用户,我想按城市搜索用户,但是如果城市变量为null,则希望所有用户

我的代码是这样的

User::where('city', $city)->orderBy('created_at')->paginate(10);
Run Code Online (Sandbox Code Playgroud)

但如果城市varible是空查询任何回报

我你这个

 User::doesntHave('city')->get();
Run Code Online (Sandbox Code Playgroud)

和这个

User::whereHas('city')->get();
Run Code Online (Sandbox Code Playgroud)

我知道我可以这样阅读我的代码

  if($city){
     User::where('city', $city)->orderBy('created_at')->paginate(10);
  } else {
    User::orderBy('created_at')->paginate(10);
}
Run Code Online (Sandbox Code Playgroud)

但一想添加其他varible我的查询和不完美

php mysql laravel

4
推荐指数
1
解决办法
1706
查看次数

标签 统计

laravel ×1

mysql ×1

pandas ×1

php ×1

python ×1