python - pandas timeseries use time relative to beginning -



python - pandas timeseries use time relative to beginning -

i reading csv log info file , using date,time fields index of frame. when plot timeseries, absolute times shown in x-axis. want show time on x-axis relative start time. how this?

for example: here sample x-axis:

23:59:57--------+23:59:58----------23:59:59--------+00:00:00--------------+

i want this:

0---------00:00:01----------00:00:02--------+00:00:03--------------+

an easy solution subtract first index-item index. can done using list comprehension, might not best (fastest) alternative if dataframe large.

begin = pd.datetime(2013,1,5,5,53) end = pd.datetime(2013,1,7,7,16) rng = pd.datetimeindex(start=begin, end=end, freq=pd.datetools.minute(15)) df = pd.dataframe(np.random.randn(rng.size), index=rng) fig, axs = plt.subplots(2,1, figsize=(15,6)) fig.subplots_adjust(hspace=.5) df.plot(ax=axs[0]) axs[0].set_title('original') df.index = [idx - df.index[0] idx in df.index] df.plot(ax=axs[1]) axs[1].set_title('normalized')

python pandas

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -