Ho un normale df.index che vorrei aggiungere alcune ore ad esso.Come aggiungere correttamente ore a un pandas.tseries.index.DatetimeIndex?
In [1]: test[1].index
Out[2]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2010-03-11, ..., 2014-08-14]
Length: 52, Freq: None, Timezone: None
Questo è come il primo elemento si presenta come:
In [1]: test[1].index[0]
Out[2]: Timestamp('2010-03-11 00:00:00')
Così provo questo per aggiungere le ore:
In [1]: test[1].index[0] + pd.tseries.timedeltas.to_timedelta(16, unit='h')
Tuttavia ottengo questo:
Out[2]: Timestamp('2010-03-11 00:00:00.000000016')
Ma vorrei ottenere questo:
Out[2]: Timestamp('2010-03-11 16:00:00')
Cosa mi manca ?. L'ambiente è Anaconda (ultima) Python 2.7.7, 2.2 ipython
Grazie mille
Puoi spiegare brevemente cosa c'è di sbagliato in ciò che ho fatto? – hernanavella
Niente. Ho appena provato un esempio in Pandas 0.14.1 e funziona come hai immaginato. unutbu ti ha fornito una soluzione alternativa che dovrebbe funzionare con le versioni precedenti dei panda (ragionevolmente più vecchi, non in età da pietra;)) –