My use case is multiple optional positional arguments, taken from a constrained set of choices, with a default value that is a list containing two of those choices. I can’t change the interface, due to backwards compatibility issues. I also have to maintain compatibility with Python 3.4. Here is my code…
Tag: python
Updating column value based on nan value of other column
I have this simple function with 2 columns. What I’m trying to do is to check what group has a number of nan and change it to a new desired value. Here’s a code snippet: Before: This is how the data looks like, you can assume numbers are sorted. In my example I know where nan and since it was
How can I prevent other threads from running when a certain condition is met?
I created a situation in which two threads run continuously. My intention is to prevent all other threads from running when the “Printing Alphabet” portion of the “printAlphabet” function is entered, and when this prioritized thread is done running, all threads resume execution until t…
Discord.py client.run and bot.run in one code
Not sure that I need to use the both runs at the same time, but: If you run this code and comment the “bot.run(‘ToKeN’)”, the first part of the code will work (def on_message), however the command ‘/help’ will not work. If you change it (comment ‘client.run(‘ToK…
Executing shell commands in Python
I’m working in Linux/Python 3 and am creating some small scripts which consist of executing some commands inside of Python. Example: Pinging a server Output: This is working OK but I don´t need to print everything. How can I get only the first line of the output? Answer You can use a subprocess in pytho…
Access data in python3 associative arrays
I’d like how to create and print associative arrays in python3… like in bash I do: In bash I can do echo “${array[“beta”,1]}” to access data to print “text2”. How can I define a similar array in python3 and how to access to data in a similar way? I tried some ap…
Create a DataFrame from list in lists (Pandas)
I´m having trouble creating a dataframe on my list. The list contains four columns, but instead it says on presente one column with data: The list itself is presented in this way: I know there is something happening due to the double [], but i can´t figure it out. Can´t someone help me? Here is the code so fa…
count ocurrences and creating a column based on the count in Python
a silly question for most of you. I have this list: I need to count how many Ins a jobName has in this list, get this count and populate a new column named Qt_Ins. it should looks like this: Could you guys help me again? Thanks Answer Input: You can use groupby with nunique: Output:
Calling Function’s return value to a script from another module?
I am new to the advanced problems of python. I am trying to get good if you want to make any correction it is welcomed. I want to do run function in Run File. I can’t pass the return value of a function without altering its value. Then assign fpath in the function firstfile.py to the secondfile.py scrip…
Can f-strings auto-pad to [the next] even number of digits on output?
Based on this answer (among others) it seems like f-strings is [one of] the preferred ways to convert to hexadecimal representation. While one can specify an explicit target length, up to which to pad with leading zeroes, given a goal of an output with an even number of digits, and inputs with an arbitrary # …