I have a class that takes only one input argument. This value will then be used to compute a number of attributes (only one in the following example). What is a pythonic way if I wanted to take the computation place only if I call the attribute. In addition, the result should be cached and attr2 must not be s…
How to indent correctly multi-line list of arguments inside function call in Python [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 1 year ago. Improve this question I want to create this multi-line function call. The examples that I fi…
How to make this code not to consume so much RAM memory?
I have these two function and when I run them my kernel dies so freaking quickly. What can I do to prevent it? It happens after appending about 10 files to the dataframe. Unfortunately json files are such big (approx. 150 MB per one, having dozens of them) and I have no idea how to join it together. EDIT: Due
How to tag a user using the discord.Member argument?
I have a discord bot with the command !sad. On execution the bot should reply with a random string from sad_list. I want the option to have the bot tag someone if you execute the command with the user: discord.Member argument. Preferred output: as opposed to only The following has already been tried: However …
Get values from dataframe with MultiIndex index containg NaNs
I cannot access the values of an index position that has a nan in it and wonder how I could solve this. (In my project this index has a very special meaning and I really need to keep it, otherwise I would need to make some dirty manual modifications: “there is always a solution” even if it is a ve…
how to combine three lists comprehension into one using only one for loop?
I have a list in range (1 to 31). The final list is l = [x, y, z] You can see my code, it is work fine using three for loops: The outputs is: I tried to do it using only one for loop. I got this error: I don’t know if I can do it or not. please help
How to subtract 1d array from 2d array’s rows in Numpy
What I want to do is to subtract 1d array from other 2d array’s rows. I found, in some case, result was wrong and confused me. Below code worked good as I wanted. Then I got following as expected. However, when I change the array “lstave” to [1, 2, 3, 4, 5] and subtract, I got following. I c…
Can’t write xlsx file to another folder
Please help me, the programmer who made this software is gone and now I’m in trouble: the program opens an xlsx file, inserts some data inside and saves it with another name, I need this file to be saved in a specific directory, can anyone help me? Thank you! Answer In wb.save (filename = self.filename)…
How to async handle callback from keyboard hotkeys?
Need to register global hotkeys. For example, f4 and f8. With keyboard library while first callback didn’t return, the next won’t call. Another words, logs like this But I want to like this Demo code I tried to use asyncio, but nothing changed Update 1 Keyboard library’s developer gave advis…
create new column based on weekly change, based on ID
I have the above data for 1 month and I want to create a new column delta_rank_7 which tells me the change in rank in last 7 days for each id (NaNs for 2021-06-01 to 2021-06-07) I can do something like mentioned here Calculating difference between two rows in Python / Pandas but I have multiple entries for ea…