Streamlib code working localy and not when I an deploy the apps

When I run the code below locally it works well without any problems.
But When I deploy the apps it is not working anymore.
Attach links to the apps below with the errors

https://github.com/Amityaron/Anomaly-detection-Option-price-/blob/main/pages/Anomaly%20detection.py

I get those errors :

The issue in anomaly detection is that spy columns is a multiindex with levels “Price” and “Ticker”, but ticker is the empty string in some cases. Add this right before the error to check:

st.write(str(spy.columns))

It shows:

MultiIndex([('Adj Close', 'SPY'), ( 'Close', 'SPY'), ( 'High', 'SPY'), ( 'Low', 'SPY'), ( 'Open', 'SPY'), ( 'Volume', 'SPY'), ( 'SMA', ''), ( 'STD', ''), ( 'Upper', ''), ( 'Lower', ''), ( 'Signal', '')], names=['Price', 'Ticker'])

Is that expected? Does it shows the same in the cloud and in your local environment?

Some of my colums like upper,lower,SMA are with Nan and contain empty cells.
But in my local environment i didn’t get any error.
Also it filter the data frame well in my local environment.
Why there is a gap between the cloud and the local environment?
Do you know how to fix it ?

Do you understand what I wrote in my previous reply and the questions I asked there? Feel free to ask if there is something you don’t understand.

e

I dont see any problems
That why i don’t know what to do and how to fix the issue with streamlit

Is that in your local environment? The different behavior can be due to a different version of some library, maybe yfinance.

If you don’t want the ticker level that appears in streamlit cloud, you can just remove it.

spy = yf.download(symbol, start=start_date, end=end_date)
spy.columns = spy.columns.droplevel("Ticker")

Can we talk via zoom or whatapp or teams
+972525072296

I totally feel stupid .
When I add this line
spy.columns = spy.columns.droplevel(“Ticker”)
I get this erorr :

KeyError: ‘Requested level (SPY) does not match index name (None)’
I am not sure it helps.

I don’t understand why in my local environment all working well and in the cloud noting work well =(.

What I suggested was adding that line right after retrieving the data.

spy = yf.download(symbol, start=start_date, end=end_date)
spy.columns = spy.columns.droplevel("Ticker")

As I said, that is probably due to different versions of something, maybe yfinance. If you want both environments to behave the same, make sure you use the same versions of everything.

It not working still the same error =(

File "/home/adminuser/venv/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
    result = func()
             ^^^^^^File "/home/adminuser/venv/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec
    exec(code, module.__dict__)File "/mount/src/anomaly-detection-option-price-/pages/Anomaly detection.py", line 25, in <module>
    spy.columns = spy.columns.droplevel(symbol)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/home/adminuser/venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 2155, in droplevel
    levnums = sorted(self._get_level_number(lev) for lev in level)[::-1]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/home/adminuser/venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 2155, in <genexpr>
    levnums = sorted(self._get_level_number(lev) for lev in level)[::-1]
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/home/adminuser/venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 2017, in _get_level_number
    self._validate_index_level(level)File "/home/adminuser/venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 2012, in _validate_index_level
    raise KeyError(

I used the same versions.
I don’t know why if i have empty cell in the data frame it not working in the cloud
while in the local environment all is working well.

Yeah, the change you made cannot work. Is there a reason why you don’t want to make the change I suggested?

Well, I cannot access your local environment so I can’t tell for sure what’s going on. All I can do is making suggestions. I have seen people being wrong about what versions they were using and even what code they were running. So I suggest you double check.

I try what you offer but it didn’t work .
can you try to run the my code send see that it work well in your local environment
but not in the cloud.

I don’t think I understand that. I This is again what I suggested:

spy = yf.download(symbol, start=start_date, end=end_date)
spy.columns = spy.columns.droplevel("Ticker")

But I cannot find that in your repo, neither in the last commit so far nor in any of the recent ones. It looks like you never made that change. Am I missing something?

For me it works the same both ways.

Hey dude, I had a similar problem in my code, and your solution fixed it. I don’t know exactly why this was happening to begin with, I remember testing my code in the cloud a few weeks ago and it worked just fine but now it just didn’t work without your solution. Thanks a lot!