Problem with pandas on streamlit cloud

Hi, I’m encountering an issue while attempting to deploy my app on Streamlit Cloud. It functions perfectly on my local environment, but it seems to face difficulties accessing specific columns in pandas or performing necessary transformations on the cloud. I’ve included a requirement text specifying the versions I use locally, and the logs indicate that these versions are correctly installed. I’ve spent several days troubleshooting the problem as it works seamlessly on my local setup. I’ve thoroughly debugged everything I could think of, yet the issue persists.

I put a snipped of the code where I am getting the problem and a shot of the problem itself. Thank you very much!

Please post your code as preformatted text, not as pixels.

Sorry, it is the very first thing i publish on a forum:

def get_stations():
    token = os.environ.get("access_token")
    url = ""
    headers = {"accessToken" : token}
    response = requests.get(url, headers = headers)
    json_data = response.json()
    stations_real_time = pd.DataFrame(json_data["data"])
    stations_real_time[["longitude", "latitude"]] = stations_real_time["geometry"].apply(lambda x: pd.Series(x["coordinates"]))
    stations_real_time = stations_real_time.drop(["geofence", "activate", "geometry", "integrator", "reservations_count", "no_available", "tipo_estacionPBSC", "virtualDelete", "virtual_bikes", "virtual_bikes_num", "code_suburb", "geofenced_capacity", "bikesGo"], axis=1)
    stations_real_time['coordinates'] = list(zip(stations_real_time['longitude'], stations_real_time['latitude']))
    return stations_real_time

I think it is ok now. Thank you.

I have been unable to even create a session after more than half an hour trying, so I cannot test the code. I suggest you review the contents of the response, it is probably not what you expect.

I don`t know what you mean by “create a session”. Is there something I can do or some more code that I can post? The response gives json data, and it works fine on the python app and the streamlit local. I have used my app many times before, so i know that the response gives that (also, I have reviewed it again). The problem is only when trying to deploy on streamlit cloud.

Response is the following json data:

So does pd.DataFrame(json_data["data"]) have a column "geometry"?

yes, it does:

Is that from your computer or from streamlit cloud?

From my computer, on stream cloud i don’t get any output like this because it doesnt let me deploy the app and the log only gives me the key error [geometry] that i posted on the first entry. I can take a screenshot of whatever you need.

Your application has been deployed, otherwise no KeyError would be raised.

Streamlit won’t log the response, but you can write code to display it.

I solved it!! As it happens, you cannot import the load_dotenv module in streamlit cloud. I had it installed and used it for my api keys and tokens, and the streamlit cloud log said it was imported successfully (but i guess it didn’t work). That is why the problem was only on the cloud.

Thank you so much! It was your message about the app being deployed that gave me the key, because I sarted debugging on the cloud version.


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.