pandas                
            Raggruppamento di dati di serie temporali
        
        
            
    Ricerca…
Genera serie temporali di numeri casuali e poi giù campione
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# I want 7 days of 24 hours with 60 minutes each
periods = 7 * 24 * 60
tidx = pd.date_range('2016-07-01', periods=periods, freq='T')
#                     ^                                   ^
#                     |                                   |
#                 Start Date        Frequency Code for Minute
# This should get me 7 Days worth of minutes in a datetimeindex
# Generate random data with numpy.  We'll seed the random
# number generator so that others can see the same results.
# Otherwise, you don't have to seed it.
np.random.seed([3,1415])
# This will pick a number of normally distributed random numbers
# where the number is specified by periods
data = np.random.randn(periods)
ts = pd.Series(data=data, index=tidx, name='HelloTimeSeries')
ts.describe()
count    10080.000000
mean        -0.008853
std          0.995411
min         -3.936794
25%         -0.683442
50%          0.002640
75%          0.654986
max          3.906053
Name: HelloTimeSeries, dtype: float64
Prendiamo questi 7 giorni di dati al minuto e scendiamo il campione ogni 15 minuti. Tutti i codici di frequenza possono essere trovati qui .
# resample says to group by every 15 minutes.  But now we need
# to specify what to do within those 15 minute chunks.
# We could take the last value.
ts.resample('15T').last()
 O qualsiasi altra cosa che possiamo fare a un oggetto groupby , alla documentazione . 
 Possiamo anche aggregare diverse cose utili. Tracciamo il min , la mean e il max di questi dati resample('15M') . 
ts.resample('15T').agg(['min', 'mean', 'max']).plot()
 Ricapitoliamo su '15T' (15 minuti), '30T' (mezz'ora) e '1H' (1 ora) e vediamo come i nostri dati diventano più fluidi. 
fig, axes = plt.subplots(1, 3, figsize=(12, 4))
for i, freq in enumerate(['15T', '30T', '1H']):
    ts.resample(freq).agg(['max', 'mean', 'min']).plot(ax=axes[i], title=freq)
Modified text is an extract of the original Stack Overflow Documentation
        Autorizzato sotto CC BY-SA 3.0
        Non affiliato con Stack Overflow
    
