Skip to content

Histogram or kde from datetime column #32590

Closed
@JulianWgs

Description

@JulianWgs

It always annoyed me that it was not possible to generate a histogram or kernel density estimation plot from a datetime column.

Is there interest in a solution following this approach?
Link to SO

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.DataFrame({"datetime": pd.to_datetime(np.random.randint(1582800000000000000, 1583500000000000000, 100, dtype=np.int64))})
fig, ax = plt.subplots()
df["datetime"].astype(np.int64).plot.hist(ax=ax)
labels = ax.get_xticks().tolist()
labels = pd.to_datetime(labels)
ax.set_xticklabels(labels, rotation=90)
plt.show()

2UUMI

I didn't look into the the pandas source code yet, but if there is interest in something like this I will look into it.

I think the main issue will be finding good x tick labels, if thats a requirement.

Greetings!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions