The following code keeps returning an AttributeError in vs code but the same code when run on Google Colab, produces no such error:
The code:
import numpy as np
import pandas as pd
url = 'https://github.com//mattharrison/datasets/raw/master/data/alta-noaa-1980-2019.csv'
alta_df = pd.read_csv(url)
dates = pd.to_datetime(alta_df.DATE)
snow = alta_df.SNOW.rename(dates)
def season(idx):
year = idx.year
month = idx.month
return year.where((month<10), year+1)
snow.groupby(season).sum()
The Error:
AttributeError Traceback (most recent call last)
File
388 year = idx.year
389 month = idx.month
--> 390 return year.where((month<10), year+1)
AttributeError: 'int' object has no attribute 'where'
My understanding is that since I am calling the season() function as param for the chained groupby function, where() function should have been able to get the year from the snow object. But somehow that is not happening.
Just to make sure that there is no syntax error in my code, ran this code on Google Colab and there I did not face any such issues. I have attached an screenshot of the output from the Google Colab for your perusal:
I have also gone through all the available solutions for AttributeError on this platform but could not find any solutions where this error was restricted only to VS Code and not to the Google Colab or Juputer Notebook terminal.

When
groupbytakes a function, it calls it on each value, this is not vectorized.You can use instead:
Or make your function non-vectorized:
Output:
Alternatively,
resample: