2017-02-23 3 views
1

だけずらし取得numpyのシリーズの日、私は次の構造を持つ時系列xを持っている:パンダ1

unique_days = np.unique(np.array(x.index.values.astype('<M8[D]'))) 
:私は次のコードを使用して、Xにだけユニークな日を取得しようとすると、今

>>> type(x) 
Out[5]: pandas.core.series.Series 

>>> x.head() 
Out[6]: 
2016-06-01 00:00:00+09:00 110.946 
2016-06-01 00:01:00+09:00 110.887 
2016-06-01 00:02:00+09:00 110.864 
2016-06-01 00:03:00+09:00 110.877 
2016-06-01 00:04:00+09:00 110.904 

>>> x.tail() 
Out[7]: 
2016-07-27 08:55:00+09:00 104.905 
2016-07-27 08:56:00+09:00 104.865 
2016-07-27 08:57:00+09:00 104.875 
2016-07-27 08:58:00+09:00 104.855 
2016-07-27 08:59:00+09:00 104.845 

>>> x.index 
Out[8]: 
DatetimeIndex(['2016-06-01 00:00:00+09:00', '2016-06-01 00:01:00+09:00', '2016-06-01 00:02:00+09:00', '2016-06-01 00:03:00+09:00', '2016-06-01 00:04:00+09:00', '2016-06-01 00:05:00+09:00', '2016-06-01 00:06:00+09:00', '2016-06-01 00:07:00+09:00', '2016-06-01 00:08:00+09:00', '2016-06-01 00:09:00+09:00', 
       ... 
       '2016-07-27 08:50:00+09:00', '2016-07-27 08:51:00+09:00', '2016-07-27 08:52:00+09:00', '2016-07-27 08:53:00+09:00', '2016-07-27 08:54:00+09:00', '2016-07-27 08:55:00+09:00', '2016-07-27 08:56:00+09:00', '2016-07-27 08:57:00+09:00', '2016-07-27 08:58:00+09:00', '2016-07-27 08:59:00+09:00'], dtype='datetime64[ns]', length=55364, freq=None, tz='Asia/Tokyo') 

は変なふうに私は得る:

>>> unique_days 
Out[9]: array(['2016-05-31', '2016-06-01', '2016-06-02', '2016-06-03', '2016-06-05', '2016-06-06', '2016-06-07', '2016-06-08', '2016-06-09', '2016-06-10', '2016-06-12', '2016-06-13', '2016-06-14', '2016-06-15', '2016-06-16', '2016-06-17', '2016-06-19', '2016-06-20', '2016-06-21', '2016-06-22', '2016-06-23', '2016-06-24', '2016-06-26', '2016-06-27', '2016-06-28', '2016-06-29', '2016-06-30', '2016-07-01', '2016-07-03', '2016-07-04', '2016-07-05', '2016-07-06', '2016-07-07', '2016-07-08', '2016-07-10', '2016-07-11', '2016-07-12', '2016-07-13', '2016-07-14', '2016-07-15', '2016-07-17', '2016-07-18', '2016-07-19', '2016-07-20', '2016-07-21', '2016-07-22', '2016-07-24', '2016-07-25', '2016-07-26'], dtype='datetime64[D]') 

だから、基本的には1日で日をシフトします。正しい日を得るための方法はありますか?

答えて

0

は私のために問題を解決しました。

1

タイムゾーンに問題があると思うのですが、それはtz-aware DatetimeIndexに変換されます。私にとって

print (x.index.tz_convert(None)) 
DatetimeIndex(['2016-05-31 15:00:00', '2016-05-31 15:01:00', 
       '2016-05-31 15:02:00', '2016-05-31 15:03:00', 
       '2016-05-31 15:04:00'], 
       dtype='datetime64[ns]', name='idx', freq=None) 

uniquedaysroundに動作します:unique_days = np.unique(x.index.date)

代わりのnp.unique(np.array(x.index.values.astype('<M8[D]')))

を使用して

print (x.index.round('D').unique()) 


print (x.index) 
DatetimeIndex(['2016-06-01 00:00:00+09:00', '2016-06-01 00:01:00+09:00', 
       '2016-06-01 00:02:00+09:00', '2016-06-01 00:03:00+09:00', 
       '2016-06-01 00:04:00+09:00'], 
       dtype='datetime64[ns, Asia/Tokyo]', name='idx', freq=None) 

print (x.index.round('D').unique()) 
DatetimeIndex(['2016-06-01 00:00:00+09:00'], 
       dtype='datetime64[ns, Asia/Tokyo]', name='idx', freq=None) 
+0

ありがとうございます、これは参考になります。しかし、今のところ、私はそれを扱うより簡単な方法があります。 – dayum