【发布时间】:2016-05-10 03:27:46
【问题描述】:
我正在尝试使用 Pandas 重新采样天气数据。原始数据的间隔大约为 5 分钟。最后,我想导出单独的 excel 文件,其中数据以 5 分钟、15 分钟和 1 小时的间隔重新采样。
我已成功将“时间”列设置为日期时间索引,但是当我尝试重新采样时,我不断收到“DataError: No numeric types to aggregate”
我也尝试过使用 converters={'TemperatureF':int...etc 导入原始 excel 文件
#Open Excel File With Original Timestamps
xlsx = pd.ExcelFile('IDLWeaterData_OriginalTime.xlsx')
df = pd.read_excel(xlsx)
print ('File read successfully')
# Set 'Time' Column as dataframe index
df.set_index(pd.DatetimeIndex(pd.to_datetime(df.Time)), inplace=True)
df.drop(['Time'],axis=1)
#Resample to 5 minute intervals
clean5 = df.resample('5min').mean()
任何有关导致此问题的原因的见解都会很棒!谢谢!
以下是数据示例:
TemperatureF DewpointF PressureIn Humidity HourlyPrecipIn dailyrainin SolarRadiationWatts/m^2
2016-01-01 00:04:00 31.9 22.2 30.51 67 0.00 0.00 0
2016-01-01 00:10:00 32.2 22.5 30.52 67 0.00 0.00 0
2016-01-01 00:16:00 32.5 23.1 30.51 68 0.00 0.00 0
【问题讨论】:
-
使用
df.dtypes,您可以看到数据框中每一列的数据类型。显然你没有任何数字列。 -
@ayhan df.dtypes 返回所有对象,索引除外。
-
@Alexander 我已经删除了所有不包含整数的列(风向等)。
-
时间 TemperatureF DewpointF PressureIn \ 2016-01-01 00:04:00 2016-01-01 00:04:00 31.9 22.2 30.51 2016-01-01 00:10:00 2016-01- 01 00:10:00 32.2 22.5 30.52 2016-01-01 00:16:00 2016-01-01 00:16:00 32.5 23.1 30.51 2016-01-01 00:22:00 2016-01-01 00:22 :00 32.5 22.8 30.52
-
好吧,至少现在我收到一条不同的错误消息...“TypeError: cannot astype a datetimelike from [datetime64[ns]] to [float64]” - 有没有办法排除日期列?
标签: python pandas resampling