1

Как сделать resample данных по получасовому интервалу с использованием усреднения для признаков Temperature, Humidity, Light, CO2, HumidityRatio. Обратить внимание, что столбец с метками класса Occupancy вместо усреднения нужно взять "как есть", т.е. resample c методом "asfreq" или "bfill". Беру данные:

 df = pd.read_csv('datatraining.txt', sep=r',', engine='python', header=None, names = ['id', 'date','Temperature','Humidity','Light','CO2','HumidityRatio','Occupancy'])
    df = df.drop([0])
    df.index = pd.to_datetime(df.date)
    df.drop('date', axis=1, inplace=True)
    df = df.apply(pd.to_numeric)
    df2 = df.copy()


id  Temperature Humidity    Light   CO2 HumidityRatio   Occupancy
date                            
2015-02-04 17:51:00 1   23.18   27.2720 426.0   721.25  0.004793    1.0
2015-02-04 17:51:59 2   23.15   27.2675 429.5   714.00  0.004783    1.0
2015-02-04 17:53:00 3   23.15   27.2450 426.0   713.50  0.004779    1.0
2015-02-04 17:54:00 4   23.15   27.2000 426.0   708.25  0.004772    1.0
2015-02-04 17:55:00 5   23.10   27.2000 426.0   704.50  0.004757    1.0




funcs = dict(Temperature ="mean", Humidity ="mean", Light="mean", CO2 ="mean", HumidityRatio ="mean",  Occupancy ="asfreq")
df2.resample('30min').agg(funcs)

Ошибка

Cannot access callable attribute 'asfreq' of 'SeriesGroupBy' objects, try using the 'apply' meth

https://drive.google.com/file/d/1YzGDML_wBZSJTGip3yZ1uk6HTTCSg_nD/view?usp=sharing

введите сюда описание изображения

Как одновременно заполнить под задачу все столбцы?

3
  • Убираю столбец Occupancy из funcs - ошибки нет
    – svil
    21 сен 2019 в 11:25
  • Использую bfiil вместо asfreq - работает, но первый столбец NaN
    – svil
    21 сен 2019 в 11:27
  • Вот так заработало без asfreq: funcs = dict(Temperature ="mean", Humidity ="mean", Light="mean", CO2 ="mean", HumidityRatio ="mean", Occupancy ="bfill") df2.resample('30min').agg(funcs).dropna()
    – svil
    21 сен 2019 в 11:30

1 ответ 1

1
funcs = dict(Temperature ="mean", Humidity ="mean", Light="mean", CO2 ="mean", HumidityRatio ="mean", Occupancy ="bfill") 

df2.resample('30min').agg(funcs).dropna()

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.