基本上,我需要的是現有表的小時平均值(見下文)。某些小時的平均值
輸入文件最初是在15分鐘的粒度。輸出結果應顯示每天的平均值,以及平均每個上午8點到下午8點在單獨列中的時間。
DateTime Value Date Output Average (entire day) Average (8am - 8pm)
09/01/2017 00:00 5055.414058 -> 09/01/2017
09/01/2017 00:15 5055.414058 10/01/2017
09/01/2017 00:30 5055.414058 11/01/2017
09/01/2017 00:45 5055.414058 12/01/2017
09/01/2017 01:00 5986.204028 13/01/2017
09/01/2017 01:15 5986.204028 14/01/2017
09/01/2017 01:30 5986.204028 15/01/2017
09/01/2017 01:45 5986.204028 16/01/2017
09/01/2017 02:00 7199.824865 17/01/2017
09/01/2017 02:15 7199.824865 18/01/2017
09/01/2017 02:30 7199.824865 19/01/2017
09/01/2017 02:45 7199.824865 20/01/2017
09/01/2017 03:00 9185.008333 21/01/2017
09/01/2017 03:15 9185.008333 22/01/2017
09/01/2017 03:30 9185.008333 23/01/2017
…
13/01/2017 22:00 94080.58174
13/01/2017 22:15 94080.58174
13/01/2017 22:30 94080.58174
13/01/2017 22:45 94080.58174
13/01/2017 23:00 93231.23486
13/01/2017 23:15 93231.23486
13/01/2017 23:30 93231.23486
13/01/2017 23:45 93231.23486
14/01/2017 00:00 91619.33743
14/01/2017 00:15 91619.33743
14/01/2017 00:30 91619.33743
14/01/2017 00:45 91619.33743
14/01/2017 01:00 89894.48751
14/01/2017 01:15 89894.48751
14/01/2017 01:30 89894.48751
…
import pandas as pd
import datetime
import numpy as np
import glob
import csv
# Local path and name of the excel file.
path = 'W:/myfolder/'
sheetname = "Forecast_" + datetime.datetime.today().strftime('%d.%m.%Y-%H')
filename = path + sheetname + ".csv"
#Create data frame of data
df = pd.read_csv(filename ,delimiter=',',engine = 'python', encoding='latin-1', index_col = False)
print(df)
table = df.groupby([df["DateTime"].dt.day, df["DateTime"].dt.hour]).mean()
print(table)
'df.mean()'怎麼辦?那是你在找什麼? –
你的代碼不工作? – IanS