【发布时间】:2020-02-11 16:38:22
【问题描述】:
我有 30 天的温度数据和其他 5 个变量,我已经将它们拆分并获取每天作为变量(第 1 天,第 2 天,第 3 天,.....,第 30 天),这是工作的第一部分是单独绘制图表,然后在图表中叠加 30 天并查看行为模式,然后在第二部分中,我需要每 10 分钟计算一次温度变量的最大值和最小值、平均值和标准偏差一天,每天获得大约 144 个值。我正在使用以下链接中的 .txt 数据:mega.nz/#!cDQGCISJ!LUD9JhJIOVGyhmS8iyHQo6x9V9KWUdfR0_T882PAv0c 每天看起来像这样:
并且我需要计算(T 的最小值和最大值,每 10 分钟的平均值和标准偏差,直到一天结束,并在其他 29 天中保持这种状态)我希望 Python 计算分钟并进行此操作:
我到目前为止的代码如下,只有第一部分(单独绘制图形的代码和 30 天的叠加图)我需要帮助:
import pandas as pd
from datetime import date
import datetime as dt
import calendar
import numpy as np
import pylab as plt
import matplotlib.ticker as ticker
import seaborn as sns
datos = pd.read_csv("Jun2019.txt", sep = ',', names=('Fecha', 'Hora', 'RADNETA', 'RADCORENT', 'RADCORSAL', 'RADINFENT', 'RADINFSAL', 'TEMP'))
datos['Hora'] = datos['Hora'].str[:9] **#Use this part to get rid of the miliseconds(mm.xxxx)**
datos['Hora']
Dia01Jun2019 = datos[datos['Fecha'] == "2019-06-01"]
tiempo01=Dia01Jun2019['Hora']
temp01=Dia01Jun2019['TEMP']
imagen = plt.figure(figsize=(25,10))
plt.plot(tiempo01,temp01)
plt.xticks(np.arange(0, 54977, 7000))
plt.xlabel("Tiempo (H:M:S)(Formato 24 Horas)")
plt.ylabel("Temperatura (K)")
plt.title("Día 01 Jun 2019")
plt.show()
imagen.savefig('D1JUN2019')
代码每天都在重复,只是我没有放在这里,原因是太长了,然后覆盖部分是(感谢 Mig B 社区用户帮助我使用以下代码):
imagen = plt.figure(figsize=(25,10))
for day in [1,2,3,4,5,6,8,11,12,13,14,15,16,17,18,19,20,23,26,27,28,30]:
dia = datos[datos['Fecha'] == "2019-06-"+(f"{day:02d}")]
tiempo= pd.to_datetime(dia['Hora'], format=' %H:%M:%S').dt.time
temp= dia['TEMP']
plt.plot(tiempo, temp) #, color = 'red' )#
plt.xlabel("Tiempo (H:M:S)(Formato 24 Horas)")
plt.ylabel("Temperatura (K)")
plt.title("Temperatura Jun 2019")
plt.show()
imagen.savefig('TEMPJUN2019')
这是迄今为止的代码,我没有计算第二部分的想法,我感谢制作第二部分的每一个帮助,记录循环for day in [1,2,3,4,5,6,8,11,12,13,14,15,16,17,18,19,20,23,26,27,28,30]:我省略了一些日子,因为他们有测量问题。
一些以前的价值信息可能可以在我在这里提出的以前的问题中找到How to make overlay plots of a variable, but every plot than i want to make has a different length of data
还有人在这里问类似的问题,如果这有助于作为指导Group the values for a certain time interval and calculate the means 只是他每 10 分钟有一次数据,并且希望每 3 小时的平均值得到 8 个一天的值,而在我的情况下,我每大约 2 分钟就有一次数据,想要每 10 分钟的平均值并得到大约 144 个一天的值。 em>
【问题讨论】:
标签: python python-3.x pandas loops statistics