-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
DataFrame.agg()
can return Series
or DataFrame
with dict
argument
#846
Comments
... while writing this I realized this is better anyway 😁 A_sum = df['A'].sum() |
You're using a 7 month old version of |
@Dr-Irv whoops, updated and seeing same thing, A_sum: np.float64 = df.agg({'A': 'sum'})
|
I'm not sure that we can fix this in terms of always returning the correct type from a static typing perspective. import pandas as pd
import numpy as np
df = pd.DataFrame([[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[np.nan, np.nan, np.nan]],
columns=['A', 'B', 'C'])
A_sum = df.agg({'A': 'sum'})
print(type(A_sum))
print(A_sum)
S_sum = df.agg({'A': 'sum', "B": 'mean'})
print(type(S_sum))
print(S_sum)
T_sum = df.agg({"A": ['sum', 'mean'], "B": ["min", "max"]})
print(type(T_sum))
print(T_sum) produces
So Having said that, we can change the type stub for I don't see how |
DataFrame.agg()
can return Series
or DataFrame
with dict
argument
I think what we should look at in case of a dictionary is the type of the dictionary values, not the number of its items. In your example, If we look at the following example: >>> U_sum = df.agg({"A": ['sum', 'mean']})
>>> print(type(U_sum))
<class 'pandas.core.frame.DataFrame'>
>>> print(U_sum)
A
sum 12.0
mean 4.0 We can see that even if the dictionary contains only one item, it returns a dataframe because it is performing two aggregations as indicated by the list |
Good point.
You can work on the 2 PR's independently. I'll be reviewing the groupby PR shortly |
Of course. I wasn’t suggesting otherwise, it is just that I need to find some free time to work on it. |
Describe the bug
There is no overload for
agg
returning a scalar, which it can per the docs and:To Reproduce
Please complete the following information:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: