pandas
ग्रुपिंग टाइम सीरीज़ डेटा
खोज…
यादृच्छिक संख्याओं के समय नमूने के बाद उत्पन्न करें
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
आइए, इस 7 दिनों के प्रति मिनट डेटा और डाउन सैंपल को हर 15 मिनट पर लें। सभी आवृत्ति कोड यहां मिल सकते हैं ।
# 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()
या किसी अन्य बात है कि हम एक के लिए कर सकते groupby
, वस्तु प्रलेखन ।
हम कई उपयोगी चीजों को भी एकत्र कर सकते हैं। आइए इस resample('15M')
डेटा के min
, mean
और max
प्लॉट करें।
ts.resample('15T').agg(['min', 'mean', 'max']).plot()
आइए '15T'
(15 मिनट), '30T'
(आधा घंटा) और '1H'
(1 घंटा) पर फिर से चलें और देखें कि हमारा डेटा कैसे स्मूद बनता है।
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
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow