Skip to content
Advertisement

Tag: python

SciPy Minimize doesn’t pass all guesses on?

I am trying to minimize a function of two variables using SciPy. The function itself is a chain of multiple lambda functions (makes it complicated but unfortunately it is the easiest way to write the expressions I need). However, when using SciPy’s minimize routine, I get the error “TypeError: () missing 1 required positional argument: ‘labour'” Strangely enough, if I

How to get which day from date in Python

I have this format of datetime in Python “2022-09-01 08:36:22”, how can I get which weekday of it? I also created this dictionary day_of_week = { 1: “sunday”, 2: “monday”, 3: “tuesday”, 4: “wednesday”, 5: “thursday”, 6: “friday”, 7: “saturday” } to get number and convert it to corresponding day. Update : september_2022[“started_at”].dt.dayofweek when I used this code I can

Count how many times can a number be divided by 2

Hi, I am a python learner and I am having problems with this homework I was given. Read a natural number from the input. Find out how many times in a row this number can be divided by two (e.g. 80 -> 40 -> 20 -> 10 -> 5, the answer is 4 times) And I should use while loop

Spyder: run a command in debug mode

I want to use the Spyder debugger (ipdb or whatever it is) from the console. It seems like the only way to enter the debugger is with the “Debug file” command, which requires me to make a dedicated file every time I want to debug something. It seems like there must be a way to do this that I just

How to define a mock object inside a mock in python?

I have a class that contains another class in a variable. Now I want to write a unit-test and define a mock object. Therefore I define a fixture in conftest.py and monkeypatch it with the mock object. I now get a the desired mock object but the inner object is noch the mock object which I defined. The problem ist

Extract first available day for each month from a csv

Stock quotes obtained from yfinance don’t start the 1st of each month, so I need to extract the the Date and Close for the first available qupte for each month in a csv. So far I managed to only get the days starting with 0, but this is still not what I want: The following is an example of what

Advertisement