groupby.DataFrameGroupBy.sum

DataFrameGroupBy.sum(numeric_only: bool = True) pd.DataFrame[source]

Compute the sum value for each group.

Parameters

numeric_only: {True, False, None} Default is True

Which datatype to be returned - True: Returns all values as float64, NaN/NaT values are removed - None: Returns all values as the same dtype where possible, NaN/NaT are removed - False: Returns all values as the same dtype where possible, NaN/NaT are preserved

Returns

pandas.DataFrame

sum value for each numeric column of each group

See Also

:pandas_api_docs:`pandas.core.groupby.GroupBy.sum`

Examples

>>> from tests import OPENSEARCH_TEST_CLIENT
>>> df = oml.DataFrame(
...   OPENSEARCH_TEST_CLIENT, "flights",
...   columns=["AvgTicketPrice", "Cancelled", "dayOfWeek", "DestCountry"]
... )
>>> df.groupby("DestCountry").sum() 
             AvgTicketPrice  Cancelled  dayOfWeek
DestCountry
AE             2.783612e+04        7.0      124.0
AR             2.058223e+05       45.0      837.0
AT             2.437872e+05       66.0     1083.0
AU             2.785365e+05       54.0     1183.0
CA             6.124173e+05      127.0     2786.0
...                     ...        ...        ...
RU             4.899533e+05       97.0     2093.0
SE             1.684563e+05       38.0      684.0
TR             4.852532e+03        1.0       19.0
US             1.183804e+06      249.0     5472.0
ZA             1.819840e+05       42.0      783.0

[32 rows x 3 columns]