Skip to content

Add DatetimeOrdinal #818

@michaelrussell4

Description

@michaelrussell4

It'd be nice to have the ability to convert datetime columns to ordinal values. The DatetimeFeatures is nice for when one wants to extract the year, month, day, etc., but sometimes it's desirable to have the date simply as an ordinal value.

Here's an example I've used in code before:

class DatetimeOrdinal(BaseEstimator, TransformerMixin):
    def fit(self, X, y=None):
        return self

    def transform(self, X):
        return X.apply(lambda x: x.map(pd.Timestamp.toordinal, na_action='ignore'))

    def inverse_transform(self, X):
        return X.apply(lambda x: x.map(pd.Timestamp.fromordinal, na_action='ignore'))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions