我有以下数据:
数据栏:
DateTime,Data1,Data2,Data3,Month,Date,Year,Hour,Minutes
1/1/2017 0:00,1.1,2.2,3.3,1,1,2017,0,00
1/1/2017 0:00,1.1,2.2,3.3,1,1,2017,0,15
1/1/2017 0:00,1.1,2.2,3.3,1,1,2017,0,30
1/1/2017 0:00,1.1,2.2,3.3,1,1,2017,1,45
我需要平均列' WS' VWS' ....' SR'每小时的数据。 DateTime列每15分钟报告一次。
答案 0 :(得分:3)
我对自己的问题有一个答案。在此发布,以便其他人可以受益:
import pandas as pd
df = pd.read_csv("MetData.csv")
df['NewDateTime'] = pd.to_datetime(df['DateTime'])
df.index = df['NewDateTime']
df_p = df.resample('H').mean()
df_p['Month'] = df['NewDateTime'].dt.month
df_p['Year'] = df['NewDateTime'].dt.year
df_p['Date'] = df['NewDateTime'].dt.day
df_p['Hour'] = df['NewDateTime'].dt.hour
writer = pd.ExcelWriter('MetData_Orig1.xlsx', engine='xlsxwriter')
df_p.to_excel(writer, sheet_name='Sheet1')
writer.save()