-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
groupby.mean, etc, doesn't recognize timedelta64 #5724
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
Worth mentioning that DataFrame's mean doesn't do this either, I think it should (convert those originally datelike to date):
Compare to |
Interestingly,
|
@hayd actually the results of
so @hayd maybe create a separate issue for this type of inference (Its just a bit of inference detection in nanops.py/_reduce) |
@hsharrison as far as the groupby; this is just not implemented ATM in groupby.py; its not that difficult, just needs to follow basically what datetime64 stuff does |
See #6884. |
Workaround: Use See https://gist.github.com/tomfitzhenry/d36ebba697a1f3eeefcb for demo. |
Wow. Any insight into why that works? I would not have expected a convenience method to take a different code path. |
Also has the same problem. @tomfitzhenry 's solution works. |
Seeing as this keeps getting kicked to the next release, you can also perform
|
BUG: allow timedelta64 to work in groupby with numeric_only=False closes pandas-dev#5724
BUG: allow timedelta64 to work in groupby with numeric_only=False closes pandas-dev#5724
BUG: allow timedelta64 to work in groupby with numeric_only=False closes pandas-dev#5724
BUG: allow timedelta64 to work in groupby with numeric_only=False closes pandas-dev#5724
BUG: allow timedelta64 to work in groupby with numeric_only=False closes pandas-dev#5724
BUG: allow timedelta64 to work in groupby with numeric_only=False closes pandas-dev#5724
BUG: allow timedelta64 to work in groupby with numeric_only=False closes pandas-dev#5724 Author: Jeff Reback <[email protected]> Closes pandas-dev#15054 from jreback/groupby_arg and squashes the following commits: 768fce1 [Jeff Reback] BUG: make sure that we are passing thru kwargs to groupby BUG: allow timedelta64 to work in groupby with numeric_only=False
This is still an issue in version 0.24.2 with both datetime64 and timedelta -type columns. If I should truncate any part of the below very long post, please let me know.
And with datetime64 series:
Dtypes:
As mentioned above, chaining with .apply and np.mean() works for timedelta only:
This same method fails with my 'start' and 'end' columns, with the error:
(the error trace for the above simulated function call is extremely long, therefor omitted) |
@sylvanosullivan You should be able to do the aggregate by setting
|
I still had some issues with this today.
This error only occurs only with If I don't try setting Using |
See http://stackoverflow.com/questions/20625982/split-apply-combine-on-pandas-timedelta-column
related as well: http://stackoverflow.com/questions/20789976/python-pandas-dataframe-1st-line-issue-with-datetime-timedelta/20802902#20802902
I have a DataFrame with a column of timedeltas (actually upon inspection the dtype is
timedelta64[ns]
or'<m8[ns]'
), and I'd like to do a split-combine-apply, but the timedelta column is being dropped:Or, forcing pandas to try the operation on the 'td' column:
However, taking the mean of the column works fine, so numeric operations should be possible:
The text was updated successfully, but these errors were encountered: