You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the "cvxpy-stocks.ipynb" notebook file, which I have downloaded locally, I am using the stocks file "bigmac.csv", to import my stock porfolio.
The line: df_returns = df_stocks.set_index('date').diff()
Returns the error TypeError: unsupported operand type(s) for -: 'str' and 'str'
I did try different permutations of the code, and interestingly, one version worked and another one did not.
The code in the example is close to this: df_stocks = pd.read_csv("bigmac.csv").iloc[500:1800] df_returns = df_stocks.set_index('date').diff() mean_stock = df_returns.mean().values
It results in the error TypeError: unsupported operand type(s) for -: 'str' and 'str'
However, the following code works: df_stocks = pd.read_csv("bigmac.csv").iloc[500:1800] df_returns = df_stocks.set_index('date') differences = df_returns.diff' #**Note that diff here has no () following** mean_stock = df_returns.mean() values = mean_stock.values print(values)
And the results are [2029.88108208 723.91574523 3.5758786 ]
So, what is the difference between the two versions and why does yours work?
Thank You
Tom Cipollone
The text was updated successfully, but these errors were encountered:
This is probably an easy fix to correct.
In the "cvxpy-stocks.ipynb" notebook file, which I have downloaded locally, I am using the stocks file "bigmac.csv", to import my stock porfolio.
The line:
df_returns = df_stocks.set_index('date').diff()
Returns the error
TypeError: unsupported operand type(s) for -: 'str' and 'str'
I did try different permutations of the code, and interestingly, one version worked and another one did not.
The code in the example is close to this:
df_stocks = pd.read_csv("bigmac.csv").iloc[500:1800]
df_returns = df_stocks.set_index('date').diff()
mean_stock = df_returns.mean().values
It results in the error
TypeError: unsupported operand type(s) for -: 'str' and 'str'
However, the following code works:
df_stocks = pd.read_csv("bigmac.csv").iloc[500:1800]
df_returns = df_stocks.set_index('date')
differences = df_returns.diff' #**Note that diff here has no () following**
mean_stock = df_returns.mean()
values = mean_stock.values
print(values)
And the results are
[2029.88108208 723.91574523 3.5758786 ]
So, what is the difference between the two versions and why does yours work?
Thank You
Tom Cipollone
The text was updated successfully, but these errors were encountered: