How should I type hint in Python a pandas DataFrameGroupBy object? Should I just use pd.DataFrame as for normal pandas dataframes? I didn’t find any other solution atm Answer DataFrameGroupBy is a proper type in of itself. So if you’re writing a function which must specifically take a DataFrameGro…
How to make a loop that keeps cheking if theres a certain class
Hello I’m trying to make a loop that keeps searching for a class with “buy” and if it finds it needs to refresh until it can’t find it anymore and then it runs the rest of the code. I’m using selenium and python help would be much appreciated. Thanks in advance Answer While not t…
In Discord.py, is it possible to wait for a variable to change from a different part of the code than the variable changes?
I tried using time.sleep(), but instead of waiting for the variable it paused the whole code, not allowing the variable to change. This is my code: I can’t figure out what to replace time.sleep(1.0) with. Answer You can use await asyncio.sleep(1) instead. Asyncio.sleep works like time.sleep, but it does…
Gaussian curve fitting in physics
I have this data, I tried to fit by a Gaussian function but I can’t found an appropriate function, I tried using curve_fit from scipy.optimize : I used this code : this is the result of this fit : Very bad fit The error message : Answer First, you’re not fitting a Gaussian function, you’re f…
Opening Anaconda Prompt with python
I want to create a script that will help me with installing packages for Spyder. Therefore, I want to use Python and have the script first open Anaconda Prompt, then execute the commands and then close that window. However, I can get it to open for example the calculator but it doesn’t seem to open the …
Thinkpython exercise leaves me puzzled about methods (Exercise 11.2)
“Read the documentation of the dictionary method setdefault and use it to write amore concise version of invert_dict” A seemingly simple exercise. But it leaves me puzzeld about the interactions of methods in python. The solution is: The documentation states: setdefault(key[, default]) If key is i…
Pandas pivot_table gives KeyError
(I’m fairly new to Python and completely new to Pandas.) I have software usage data in a tab-separated txt file like this: The DataFrame is imported correctly, and groupby methods like this work all right: However, when I’m trying to create a pivot table with this line: I get where the “key&…
Groupby and get the values in one dataframe
I have a dataframe which I need to do groupby by multiple columns and get the items within every group as a row; I need to output a below table after group; I have been looking for the answer but I was not able to find any, I appreciate if you can help we with the code. Answer You could
Compare all elements of a list
To illustrate my problem, imagine I have a list and I want to compare each element with the next one to check if they are the same value. The problem is that when I try to access the last element of the list and compare it with “the next one”, that one is out of range, so I would get
How to access a content of file which is passed as input artifact to a script template in argo workflows
I am trying to access the content(json data) of a file which is passed as input artifacts to a script template. It is failing with the following error NameError: name ‘inputs’ is not defined. Did you mean: ‘input’? My artifacts are being stored in aws s3 bucket. I’ve also tried u…