When I run the code with the code runner extension the code shows in the terminal however when it gets to the input function it freezes like its asking me to input some data however I cant eve type a number or letter. This is what the terminal shows… Answer Code Runner shows results in OUTPUT and doesn&…
how to do nested loop using apply in pandas
I have a data frame like this: I want o apply a function on pos and save the result in a new column. So the output would look like this: So the function return a list for each tuple in the list (but the implementation of the function is not the point here, for that I just call get_sentiment). I
How to get a list of dictionaries sorted by three criteria
I want to get a list sorted accordingly to the following rules persons.sort(key = lambda p: (abs(p[“height”] – 180), p[“weight”]==75, p[“weight”])) i.e. I need it to get sorted firstly by its closeness to the height 180, then all of the weight values which are equal t…
How to skip some results using double for loop?
I have a problem, so I made it simplified code, everything how it is here need to stay that way because of my bigger problem. I have 2 dictionaries and I have 2 for loops. I need to skip outputs with same result like AA, BB, CC etc… and I need to remove one of AB or BA, I need
Sort a dict of DataFrames
I have a dict of data-frames like the following: symbols ={BTC: DF, ETH: DF, DOGE:df} where each DF looks like this. I am trying to sort the dict by the price_change in the last row. Answer You could figure out the sorting of the keys by using a lambda function on sorted, which gets the last price change per …
Have each loop iteration create a new line of data in a file
I found and edited some code that records water flow data off of a flowmeter. I have managed to edit the script to run for only 5 mins and write to a file (I tried a .csv file but I am realizing this may not be entirely possible). However, when the script runs, the data file created just lists one
Python Chest Opening Odds
I’ve been trying to figure out how to recreate odds in python for a chest opening game thingy, but the random.choice isn’t really considering different odds. The goal I’m trying to achieve is set certain odds for different “rarities”, like for example having 50% probability for g…
Python argparse – Detect if list argument is passed without anything afterwards
Let’s say the user types: ./args.py –create –mem 5 and my parser looks like this: parser.add_argument(‘–create’, nargs=’*’, default=None) Normally –create takes a list with nargs=’*’, however in this case the user passed nothing. What I would l…
Return type based on type argument
I have this code, which type checks fine on its own: But if I try to use it: I get Incompatible return value type (got “Tuple[BaseObject, …]”, expected “Tuple[DerivedObject, …]”)mypy(error) I can fix this with But what I would really like to do is specify that df2objects re…
Python: urllib.parse.quote_plus and edit string
I need to add a wild card to a urllib.parse.quote_plus command but I am unclear how to. When I execute the following on my flask server, I get the following error: How might I add a wildcard in here to accept an object? Answer i think you should do the replacing first or