Trying to get rid of for loop to speedup the execution in filling values in Column ‘C’ based on if, elif conditions involving multiple columns and rows. Not able to find a proper solution. tried applying np.where with conditions, choices and default values. But failed to get expected results as i …
Tag: python
Destructor usage in python __del__()
Will the following not cause issue of freeing memory twice? Why is python3 destroying an object when it has already been destroyed by the programmer? Output: Answer By calling __del__() you’re just calling a method on the instance, without any special meaning. The __del__() method, both yours and by def…
Sympy calculation on tan function
I have a problem when simplifying a symbolic expression in sympy when having a trigonometric function and a complex exponent, namely I just assumed a different definition of tan function, and I have a weird thing going on. So I do: Symbolic variable sym.simplify(test2) is equal to -tan(a) and normaly test1 va…
save data to new worksheet, in existing workbook using python
created a new dataframe named df3 and saved to excel workbook named masterdata.xlsx, later created another dataframe named table when I try to write that dataframe to sheet2 of masterdata.xlsx, it overrighted the first created dataframe. masterdata.xlsx have two sheets, sheet1 and sheet2. sheet1 have some dat…
how to match the keys of a dictionary and return their values?
I have two dictionaries: Both dictionaries contains the same amount of key_value pairs. In dictionary x, the key is the translation in Bulgarian of names of languages and the values are the names of the same languages in English. in dictionary y, the keys are the name of the languages in Bulgarian and the val…
Python Pandas – How to compare values from two columns of a dataframe to another Dataframe columns?
I have two dataframes which I need to compare between two columns based on condition and print the output. For example: df1: df2: I want to write a code which compares ID column and date column between two dataframes is having a conditions like below, if “ID and date is matching from df1 to df2”: …
fetch_balance method in ccxt won’t return all assets
As I call the fetch_balance method from kucoinfutures in ccxt, it only returns BTC, not any other assets. Shouldn’t there be other assets like USDT or ETH too? Here’s the python code: Here’s what I get from print(balance): Am I missing something? Answer It seems like fetchBalance only return…
NameError: name ‘VideoCapture’ is not defined [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 11 …
How to take a screenshot from part of screen with mss python?
I have a simple code here: result.png But I want to take a part of screen like this: Thanks for help! Answer As explained on https://python-mss.readthedocs.io/examples.html, something like this should work: This is just the example given on the website. You can adjust the part of the screen that you are takin…
Retry async aiohttp requests for certain status codes
What is the best way to retry async API calls using aiohttp? I want to retry the request for the standard socket error, timeout error, etc as well as for certain status codes 500, 501. I have tried using aiohttp_async, but can’t get it to work: Output: Answer It looks like you have installed aiohttp_ret…