Reputation: 2147
I have two daily series and I have to merge them into one hour series with the 1st series for the first 12 hours and the 2nd series for the remaining hours.
Is there a more efficient way instead of building a list manually and convert it to series? Thanks
a = pd.Series(np.random.rand(5), pd.date_range('2015-01-01', periods=5))
b = pd.Series(np.random.rand(5), pd.date_range('2015-01-01', periods=5))
c = an hourly series
Upvotes: 3
Views: 73
Reputation: 77951
possibly:
>>> b.index += dt.timedelta(hours=12)
>>> pd.concat((a, b), axis=0).sort_index()
2015-01-01 00:00:00 0.150
2015-01-01 12:00:00 0.970
2015-01-02 00:00:00 0.746
2015-01-02 12:00:00 0.937
2015-01-03 00:00:00 0.523
2015-01-03 12:00:00 0.392
2015-01-04 00:00:00 0.606
2015-01-04 12:00:00 0.459
2015-01-05 00:00:00 0.221
2015-01-05 12:00:00 0.029
dtype: float64
and, ts.asfreq('H', method='ffill')
to have hourly frequency.
Upvotes: 1