Skip to content

Tag: python

Declare type annotation for optional dependency

Lets say I want to declare an input type originating from an optional dependency of my library. I have the option to set it as a string, at least to make Python happy (e.g. not complain about the missing name). But then Mypy will of course not know what to do about this missing type. Is there any solution, wi…

Pandas datetime filter

I want to get subset of my dataframe if date is before 2022-04-22. The original df is like below df: I checked data type by df.dtypes and it told me ‘date’ column is ‘object’. So I checked individual cell using df[‘date’][0] and it is datetime.date(2022, 4, 21). Also, df[&#…

Graphing Inequalities in python

I’m looking to create a program that will randomly generate lines (that are inequalities) and that will show the area that satisfies the constraints. I don’t mind which libraries are used so feel free to use sympy, numpy etc I will show my current code but this just fills the area between 2 lines …

pygame sprite move faster if window is smaller

my character sprite moves faster if my game is in window mode. to set the velocity i used ROOTwidth, in theory the velocity should be scaled… this is my code (simplified) I don’t know what to do… for every element in my game, using ROOT dimensions works fine, only in velocity I have problems…

Security & Pyscript

I am coding a Python editor, which can execute python codes and returns the output. My initial idea was to code a backend service for it, that will run the Python script and return the output. However with the release of Pyscript, I am wondering if I can do it in the frontend. One of my biggest concerns is th…

Index must be DatetimeIndex when filtering dataframe

I then have a function which look for a specific date (in this case, 2022-01-26): Which returns: When I then try to look for only times between 09:00 and 09:30 like so: I get the following error: Full code: What am I doing wrong? Answer between_time is only valid if your index is a DateTiimeIndex As your stri…