Creating Data Histograms/visualizations Using Ipython And Filtering Out Some Values
I posted a question earlier ( Pandas-ipython, how to create new data frames with drill down capabilities ) and it was pointed out that it is possibly too broad so I have some more
Solution 1:
I think you need to convert duration (timedelta64) to int (assuming you have a duration). Then the .hist method will work.
from pandas import Series
from numpy.random import rand
from numpy import timedelta64
In [21]:
a = (rand(3) *10).astype(int)
a
Out[21]:
array([3, 3, 8])
In [22]:
b = [timedelta64(x, 'D') for x in a] # This is a duration
b
Out[22]:
[numpy.timedelta64(3,'D'), numpy.timedelta64(3,'D'), numpy.timedelta64(8,'D')]
In [23]:
c = Series(b) # This is a duration
c
Out[23]:
03 days
13 days
28 days
dtype: timedelta64[ns]
In [27]:
d = c.apply(lambda x: x / timedelta64(1,'D')) # convert duration to int
d
Out[27]:
031328
dtype: float64
In [28]:
d.hist()
I converted the duration to days ('D'), but you can convert it to any legal unit.
Post a Comment for "Creating Data Histograms/visualizations Using Ipython And Filtering Out Some Values"