0

i have a problem i running this code

resamp = pd.DataFrame()
station_ids = list(set(weather_data.station_id.tolist()))
for _id in station_ids:
idx = weather_data.station_id == _id
ti = time_index[idx]

wdfi = weather_data[idx].set_index(ti)
floating = wdfi[['visibility','temperature','wind_speed', "wind_dir", "Rain"]]
binaries = wdfi[['visibility','temperature','wind_speed', "wind_dir", "Rain"]]
b = binaries.resample('1h').rolling(24).apply(lambda x: x.any())
f = floating.resample('1h').agg({
    'wind_speed': 'mean',
    'visibility': 'mean',
    'temperature': 'mean',
    'wind_dir':'mean',
    'Rain':'mean'
})

temp = pd.concat((f,b),axis=1)
temp['station_id'] = _id
resamp = resamp.append(temp)

and I get this error

AttributeError Traceback (most recent call last) in () 8 floating = wdfi[['visibility','temperature','wind_speed', "wind_dir", "Rain"]] 9 binaries = wdfi[['visibility','temperature','wind_speed', "wind_dir", "Rain"]] ---> 10 b = binaries.resample('1h').rolling(24).apply(lambda x: x.any()) 11 f = floating.resample('1h').agg({ 12 'wind_speed': 'mean',

~\Anaconda3\envs\arcpro\lib\site-packages\pandas\core\resample.py in getattr(self, attr) 95 return self[attr] 96 ---> 97 return object.getattribute(self, attr) 98 99 @property

AttributeError: 'DatetimeIndexResampler' object has no attribute 'rolling'

my pandes v 24 thank you

Maram Mubarak
  • 323
  • 2
  • 3
  • 11

1 Answers1

1

answer by SvenD could be what you're looking for : How to convert DatetimeIndexResampler to DataFrame?

"resample no longer returns a dataframe: it's now "lazily evaluated" at the moment of the aggregation or interpolation. => depending on your use case, replacing .resample("1D") with .resample("1D").mean() (i.e. downscaling) or with .resample("1D").interpolate() (upscaling) could be what you're after, and they both return a dataframe.

– Svend Sep 15 '16 at 8:57"

Sri Sankaran
  • 8,120
  • 4
  • 38
  • 47