简体   繁体   中英

Trouble resampling data in Pandas

I'm trying to resample weather data with Pandas. The original data is in roughly 5 minute intervals. Eventually, I would like to export separate excel files with data resampled at 5 minute, 15 minute, and 1 hour intervals.

I have successfully set 'Time' column as datetime index, but when I try to resample, I keep getting "DataError: No numeric types to aggregate"

I have also tried importing the original excel file with converters={'TemperatureF':int...etc

#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()

Any insight into what is causing this problem would be great! Thanks!

Here is a sample of the data:

                    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

This is what is happening with your data.

在此处输入图片说明

To fix it:

>>> df[df.Time.notnull()].set_index('Time').astype(float).resample('5min')
                 TemperatureF  DewpointF  PressureIn  Humidity  HourlyPrecipIn  

dailyrainin  SolarRadiationWatts/m^2
Time                                                                                                                    
2016-01-01 00:00:00          31.9      22.20       30.51        67               0            0                        0
2016-01-01 00:05:00           NaN        NaN         NaN       NaN             NaN          NaN                      NaN
2016-01-01 00:10:00          32.2      22.50       30.52        67               0            0                        0
2016-01-01 00:15:00          32.5      23.10       30.51        68               0            0                        0
2016-01-01 00:20:00          32.5      22.80       30.52        67               0            0                        0
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM