Syntaxerror: invalid syntax data.append)=(R)

Asked

Viewed 37 times

-1

It’s giving a syntax error but I believe that’s not it, but I can not identify what’s wrong:

```python
#retorno

df = carteira.copy()
df = df.reset_index()

colunas = df.columns
columns = list(colunas[1:])

df_rent = df(['Date'])
n = len(df_rent)

for coluna in colunas:
  data = [0]
  for idx,val in df.iterrows():
    if idx > 0:
      R = math.log(df.loc[idx,coluna] / (df.loc[idx-1,coluna])
      data.append(R)
      
  df_rent[coluna] = data 
```

>  File "<ipython-input-109-818eeabca8c6>", line 17
    data.append(R)
       ^
SyntaxError: invalid syntax

1 answer

0


On the line:

...
R = math.log(df.loc[idx,coluna] / (df.loc[idx-1,coluna])
...

There’s a ( which was not closed shortly after the /. And this is causing the error of Invalid Syntax.

Just remove these parentheses and the error will stop happening:

...
R = math.log(df.loc[idx,coluna] / df.loc[idx-1,coluna])
...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.