簡體   English   中英

選擇一系列時間序列數據並執行數據分析

[英]Selecting a range of time-series data and performing data analysis

我有一個監視設備,可以監視溫度,壓力和濕度。 有了這些數據,我得到了測量的日期和時間。 每5秒鍾進行一次測量。 我想編寫一個函數,為我提供特定日期和時間范圍內溫度,壓力和濕度的平均和標准偏差。 理想情況是這樣的...

def TempPressHumid(time_start, time_end, data_start, date_end, temp_data, press_data, humid_data)

到目前為止,我有這個:

import pandas as pd
import numpy as np

df = pd.read_csv('TM4CVC.csv', index_col = 0)

temp_data = df['Temperature']
temp_av = np.mean(temp_data)
temp_sd = np.std(temp_data)

humid_data = df['humidity']
humid_av = np.mean(humid_data)
humid_sd = np.std(humid_data)

press_data = df['pressure']
press_av = np.mean(press_data)
press_sd = np.std(press_data)

這可能嗎?

謝謝,

喬伊

這應該做。 按時間和日期切片df。 如果您只需要連續的日期時間范圍,而不必每次都選擇時間和日期,則可以將功能更改為僅接受日期,然后使用格式'yyyy-mm-dd hh:mm:ss'對其進行切片。

import pandas as pd
import numpy as np
import random

def TempPressHumid(time_start, time_end, date_start, date_end, df):

    temp = df[date_start:date_end]
    temp = df.between_time(time_start,time_end)

    out = {'temp_avg':np.mean(temp['temp']),
    'temp_std':np.std(temp['temp']),
    'press_avg':np.mean(temp['press']),
    'press_std':np.std(temp['press']),
    'humid_avg':np.mean(temp['humid']),
    'humid_std':np.std(temp['humid'])}
    print out


df = pd.DataFrame({'temp':[random.randint(50, 80) for x in range(51841)],
    'press':[random.randint(20, 40) for x in range(51841)],
    'humid':[random.randint(20, 80) for x in range(51841)]}, 
    index = pd.date_range(start = '2014-01-01', end = '2014-01-04', freq = '5S'))

TempPressHumid(time_start = '01:00:00', time_end = '23:00:00', date_start = '2014-01-02', date_end = '2014-01-03', df = df)

這將獲取2014年1月2日至2014年1月3日之間凌晨1點至晚上11點之間的所有數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM