Skip to content

DataFrame.mean() ignores datetime series #28108

Closed
@BlaneG

Description

@BlaneG

Code Sample, a copy-pastable example if possible

In [1]: import pandas as pd
In [2]: from datetime import datetime

In [3]: s = pd.Series([datetime(2014, 7, 9), 
   ...:            datetime(2014, 7, 10), 
   ...:            datetime(2014, 7, 11)])

In [4]: df = pd.DataFrame({'numeric':[1,2,3],
   ...:               'datetime':s})

In [5]: df.mean()
Out[5]: 
numeric    2.0
dtype: float64

In [6]: s.mean()
Out[6]: Timestamp('2014-07-10 00:00:00')

Problem description

[this should explain why the current behaviour is a problem and why the expected output is a better solution.]

As of pandas 0.25 it is possible to apply mean() to a datetime series. However, DataFrame.mean() ignores datetimes series columns rather than returning the mean of the datetime series as one might expect.

Expected Output

When axis=0, output could be a dataframe with dtype as the first row, and the value as the second row.

Metadata

Metadata

Assignees

Labels

Nuisance ColumnsIdentifying/Dropping nuisance columns in reductions, groupby.add, DataFrame.applyNumeric OperationsArithmetic, Comparison, and Logical operationsReduction Operationssum, mean, min, max, etc.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions