[英]Calculating monthly averages of daily temperature data including negative and positive values
I am trying to calculate monthly average temperatures for a dataset with daily temperature values that spans three years.我正在尝试计算具有跨越三年的每日温度值的数据集的月平均温度。 With the data.frame appearing like this example"
随着 data.frame 出现像这个例子“
Date Month Temperature
12-2-2016 December -10
12-3-2016 December -12
01-2-2017 January -15
01-3-2017 January -14
02-3-2017 February 3
02-4-2017 February 7
03-2-2017 March 8
03-3-2017 March 9
I tried running the following code in order to create a new dataframe with the Month and the average temperature:我尝试运行以下代码以创建一个带有月份和平均温度的新 dataframe:
group_by(df$month) %>%
summarise(mean_airtemp = mean(Temperature))
However, when running this code I get NA for certain months which I believe is attributed to negative values.但是,在运行此代码时,我会在某些月份得到 NA,我认为这归因于负值。 I have tried to figure it out but have only found solutions that seem to separate the values based on whether they are negative or positive.
我试图弄清楚,但只找到了似乎根据它们是负值还是正值来区分值的解决方案。
you can use groupby
of month and temp together你可以一起使用
groupby
of month 和 temp
df.groupby(['Month'])['Temperature'].mean().reset_index(name = 'avg')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.