-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DataFrame.asof #2941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Any thoughts on this? Right now DataFrame.asof() can be emulated via df.apply(lambda x: x.asof(some_series)) But this is wasteful because it searches each column redundantly. |
this is pretty straightforward to do for a frame, (its very similar to the series logic), in fact I would move to |
@jreback I can take a stab at it this weekend if you like. |
that would be awesome! |
@jreback The biggest issue I see is that df = pd.DataFrame({'letter':['a', 'b', 'c'], 'number':[1, 2, 3]})
df.apply(lambda x: pd.core.common.take_1d(x.values, [-1, 1])) Here is a quick-and-dirty hack that produces what I'm looking for: In [20]: pd.DataFrame(dict(zip(df.columns, map(lambda x: pd.core.common.take_1d(df[x].values, [-1, 1]), df.columns))))
Out[20]:
letter number
0 NaN NaN
1 b 2 |
you can just use DAtaFrame.take |
@jreback That just treats the -1 the same way regular Python does: wrapping around the end of the array: In [4]: df.take([-1, 1]) # doesn't matter what I set 'convert' to
Out[4]:
letter number
2 c 3
1 b 2 I'm looking for a way to return a |
you need to look at the internal functions for this, eg take_2d or you can 1s take with a flattened array then reshape |
I've been toying with this a little and it's not clear that it's possible to avoid doing the asof_locs call for each column, since they might have missings in different positions. So you probably dont end up gaining much over what the df.apply(lambda s: s.asof(t)) approach gives you. However, if you don't want missings to be ffilled, then you only need to do it once. Perhaps it makes sense to have a flag argument which indicates whether the user wants missings to be ffilled during the asof operation? |
Yep, let's close it. |
closes #1870 xref #2941 http://nbviewer.jupyter.org/gist/jreback/5f089d308750c89b2a7d7446b790c056 is a notebook of example usage and timings Author: Jeff Reback <[email protected]> Closes #13358 from jreback/asof and squashes the following commits: 4592fa2 [Jeff Reback] TST: reorg tests/series/test_timeseries -> test_asof
like Series.asof, should also take skipna={none, 'any', 'all'}
The text was updated successfully, but these errors were encountered: