0

I want to get the yearly mean of a list of values associated with a zip code the problem I get this error code, can you please help me out.

My DataFrame

My code is:

np.random.seed(2020)
rng = pd.date_range('2/9/2017', '3/19/2019', freq='10T')
df2 = pd.DataFrame({'SCORE':np.random.randint(1000, size=len(rng))}, index=rng)
out = pd.Series({x: df2.loc({x: df2.loc[f'02/9/{x}', :f'03/19/{x+1}', 'SCORE'].mean()
                 for x in range(df2.index.year.min(), df2.index.year.max()+1)})

The error is:

  File "<ipython-input-150-61dcc574e6e3>", line 1
    out = pd.Series({x: df2.loc({x: df2.loc[f'02/9/{x}', :f'03/19/{x+1}', 'SCORE'].mean()
                                                       ^
SyntaxError: invalid syntax
Khan
  • 39
  • 6

1 Answers1

0

You miss a coma between f'02/9/{x}' and :f'03/19/{x+1}':

np.random.seed(2020)
rng = pd.date_range('2/9/2017', '3/19/2019', freq='10T')
df2 = pd.DataFrame({'SCORE':np.random.randint(1000, size=len(rng))}, index=rng)
out = pd.Series({x: df2.loc({x: df2.loc(f'02/9/{x}', f'03/19/{x+1}', 'SCORE').mean()
                 for x in range(df2.index.year.min(), df2.index.year.max()+1)})
Federico Baù
  • 6,013
  • 5
  • 30
  • 38