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…
Tag: python
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 …
How to extract ids and rows only if a column has all of the designated values
I have the following dataframe I want to group by id and keep those ids if it contains all of the designated values (i.e. 2019Q4, 2020Q4, 2021Q4) then extract rows that correspond to those values. isin() won’t work because it won’t drop C and D. desired output Answer You can use set operations to …
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…
peer to peer connection to a computer in external network using python socket library
I am trying to create a peer-to-peer python app using the socket library. I am curious to know if there is any way in which I can use the socket library to connect to another computer outside my local network without any manual steps like opening ports on the router for port forwarding. Do I need to use an al…
How might I find an approximate solution to this equation?
The following code is meant to find for how much Bitcoin one is meant to buy in order to break even given the expected inflation, the holding period, and the amount of savings in dollars: When the program is fed with years=3, times=4, cpi=8, and a=1000 it does not find a solution. Because of it I introduced a…
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…
Django forms not saving posts to database
i am trying to create a course from my frontend using django form, everything seems fine but when i hit the create button it just refreshes the page without saving to database or throwing back any error, and that is not what i am expecting. create-course.html models.py forms.py Answer this was fixed by just u…