-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
Milestone
Description
I rewrote this StackOverflow question to include an example. I think this looks like a bug (possibly in num2date
or date2num
)?
I read-in a file and plot it with pandas DataFrame
. The index is DatetimeIndex, and then I use ginput(1)
method to get one point, however the coordinate which I get is wrong.
The code is as follows:
import pandas as pd
from matplotlib.dates import num2date, date2num
ts = pd.date_range('2012-04-12,16:13:09', '2012-04-14,00:13:09', freq='H')
df = pd.DataFrame(index=ts)
df[0] = 20.6
I then plot and click on the graph using ginput:
df.plot()
t = pylab.ginput(n=1) #click somewhere near 13-APR-2012
However, the first item appears to be a float
In [8]: x = t[0][0] # ~ 370631.67741935479
In [9]: num2date(x)
Out[9]: datetime.datetime(1015, 10, 3, 16, 15, 29, 32253, tzinfo=<matplotlib.dates._UTC object at 0x104196550>)
# this is way out!
The docs suggest that it should be using these floats (from datetonum
):
In [10]: dt = pd.to_datetime('13-4-2012', dayfirst=True)
In [11]: date2num(dt)
Out[11]: 734606.0
What is this float, and how can I convert it to a datetime?
Note: If I remove one of the rows from the dataframe this works correctly:
df1 = df.drop(ts[1], axis=0)
...
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
Select code repository
Activity
changhiskhan commentedon Dec 12, 2012
I answered on stackoverflow. there's some conversion going on in the first case when the index has a regular frequency
wesm commentedon Apr 9, 2013
Moved this to 0.12
jreback commentedon Sep 22, 2013
@cpcloud want to assign yourself? (for 0.14)
cpcloud commentedon Sep 22, 2013
sure thing 😄
cpcloud commentedon Dec 12, 2013
@jreback, @jtratner What should this return? I think Chang's solution is fine, not sure this is under pandas purview, per se.
jreback commentedon Mar 11, 2014
@hayd close this, or just push to 0.15 as a reminder?
cpcloud commentedon Jun 9, 2014
Closing, as this works.