Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Histogram or kde from datetime column #32590

Closed
JulianWgs opened this issue Mar 10, 2020 · 11 comments · Fixed by #36287
Closed

Histogram or kde from datetime column #32590

JulianWgs opened this issue Mar 10, 2020 · 11 comments · Fixed by #36287

Comments

@JulianWgs
Copy link

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!

@jbrockmendel jbrockmendel added the Visualization plotting label Jun 5, 2020
@JulianWgs
Copy link
Author

An answer would be appreciated :)

@JulianWgs JulianWgs changed the title Histogram oder kde from datetime column Histogram or kde from datetime column Jul 27, 2020
@JulianWgs
Copy link
Author

An answer is still appreciated :)

@JulianWgs
Copy link
Author

@jbrockmendel

@jbrockmendel
Copy link
Member

I have no strong opinion on this. The SO link appears to have a few viable options.

@JulianWgs
Copy link
Author

JulianWgs commented Sep 4, 2020 via email

@jbrockmendel
Copy link
Member

cc @datapythonista thoughts?

@datapythonista
Copy link
Member

A datetime is a float under the hood, and we support floats, so I think it shouldn't be difficult to make this work. The approach would be similar to the code that you showed (I think casting to float makes more sense than casting to int, but the idea is the same). Feel free to open a pull request for this.

@onshek
Copy link
Contributor

onshek commented Sep 9, 2020

Hi everyone here. I find it a little strange: data["datetime"].hist() can work well for calling hist_series() which dose not check whether the data is numerical. While data.hist() calls hist_frame() and fails at data = data._get_numeric_data() for data here has no columns any more and breaks down in Line415 resulting the final ValueError.
Could you give me more suggestions and I would like to have a try to fix this.
@jbrockmendel @datapythonista @JulianWgs @jreback @charlesdong1991

@AleGuarnieri
Copy link

take

@AleGuarnieri AleGuarnieri removed their assignment Oct 1, 2020
@JulianWgs
Copy link
Author

JulianWgs commented Oct 1, 2020 via email

@charlesdong1991
Copy link
Member

hey, @AleGuarnieri and @JulianWgs

thanks very much for your interests in working on it, however, as you noticed, there is an open PR which solves this issue, and probably it looks pretty much close to being merged

So feel free to look around other issues! thanks!

@jreback jreback added this to the 1.2 milestone Oct 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants