Skip to content

ENH: New method "ends" as a combination of “head” and "tail" #61860

Open
@JoergVanAken

Description

@JoergVanAken

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I often work with time series and want to see at a glance where and how they begin and end.

Feature Description

That's why I registered an "ends" accessor, which provides me with both ends in one call as a combination of "head" and "tail". It's really simple, but very usefull to me:

class _EndsAccessor:
    def __init__(self, pandas_obj):
        self._obj = pandas_obj

    def __call__(self, n=2):
        return pd.concat([self._obj.head(n), self._obj.tail(n)])

@pd.api.extensions.register_dataframe_accessor("ends")
class EndsAccessorDataframe(_EndsAccessor):
    pass


@pd.api.extensions.register_series_accessor("ends")
class EndsAccessorSeries(_EndsAccessor):
    pass

Alternative Solutions

We leave it as it is and I continue using the solution shown above.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions