A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/20647 below:

center=True in expanding operations returns non-sensical results · Issue #20647 · pandas-dev/pandas · GitHub

What is center=True supposed to do in df.expanding()... operations?

Using the example from the docstring of .expanding():

In [103]: df = DataFrame({'B': [0, 1, 2, np.nan, 4]})

In [105]: df.expanding(2).sum()
Out[105]: 
     B
0  NaN
1  1.0
2  3.0
3  3.0
4  7.0

Now adding center=True:

In [106]: df.expanding(2, center=True).sum()
Out[106]: 
     B
0  3.0
1  3.0
2  7.0
3  7.0
4  6.0

Two observations: it seems it just shifted the first rows (which is not the same as centering) and I don't know where the last values are coming from (and they should certainly not decrease again in an expanding sum with only positive values).

Further, I also cannot think of what it actually should do. If we really want to center it, that would mean returning with a new index (as the real center would only increase with 0.5 and be something like [0, 0.5, 1, 1.5, 2] for those data).

So maybe we should rather remove this keyword for expanding ?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4