loops

Looping through ("Spanning across") dates in Python with variable months and years?

Looping through ("Spanning across") dates in Python with variable months and years? Question: My requirement is to loop through calendar dates in python in 2-day increments capturing every date across multiple months or years without repeating any dates. I’m sure that sounds confusing so I’ve posted some reference visuals to demonstrate. I have written Python …

Total answers: 2

Need to loop through a list and perform operations between each object

Need to loop through a list and perform operations between each object Question: So I need to loop through a list and in between each object and the next, perform an operation, whether it’s addition, subtraction, or multiplication, however each time I iterate, my code only ends up using one operator, and not a combination. …

Total answers: 1

For loop to update multiple dataframes

For loop to update multiple dataframes Question: I wrote a few for loops and they all have the same issue: they do the correct operation, but do not overwrite the desired result in the old pandas dataframe. Here is what it looks like. Example data: TimeStamp [µs] Source Channel Label Value [pV] 0 402600 F10 …

Total answers: 1

I don't understand why my code is looping when not supposed to

I don't understand why my code is looping when not supposed to Question: This is very simple, and I may look dumb, I’m completely new to Python In my function user(), I put a while loop to see that only 1 word is entered and no numbers. Its a vowel counter that accepts 1 word …

Total answers: 2

Trying to make an online slots click bot

Trying to make an online slots click bot Question: I’m trying to code a bot in Python that will play a demo slot game for me. I want the bot to click a button when it appears on screen, a certain number of times. So for example, at the start of the game, the bot …

Total answers: 1

Trying to plot two variable function, calculating function loop gives wrong shape

Trying to plot two variable function, calculating function loop gives wrong shape Question: I have some function f, which is some compliciated integral taking two parameters x and y . I want to make contour plot in this parameter space (i.e. over some arrays X and Y), so I use loops over those two paremeters. …

Total answers: 1

Pandas dataframe duplicates – Python

Pandas dataframe duplicates – Python Question: I have a simplified dataframe like this: ID RecordingType Date Value 1 FEVR 2019-05-22 18:37:10 1.36 1 FEVR 2019-05-22 18:41:12 1.35 1 FEVR 2019-05-22 18:45:16 1.35 I am trying to run this code: df = df.sort_values(by=[‘ID’, ‘RecordingType’, ‘Date’], ascending=True).reset_index().drop(columns=["index"]) df["ToRemove"] = False dict_temp_df = df.to_dict("records") outputcolnames = {‘FEVR’:’Value’} for …

Total answers: 2

iterator function does not iterate over all elements

iterator function does not iterate over all elements Question: I have two functions: # function to get number of wanted atom def atom_number_grabber(sum_formula, wanted_atom): match = re.match(r"([A-Z][a-z]*)([0-9]*)", sum_formula, re.I) if match: items = match.groups() if items[0] == wanted_atom: atom_number = items[1] if not atom_number: atom_number = "1" return atom_number else: pass and #function to iterate …

Total answers: 1

List of coordinates filtering

List of coordinates filtering Question: In python I have a list of contours (each holding x, y, w, and h integers), I need to somehow iterate over the list and check, if the current x + w is greater than the last x + w by less than 3 (which mean by 1 or 2) …

Total answers: 1

How to join strings into one sentence separated by spaces

How to join strings into one sentence separated by spaces Question: I have this code: with open("wordslist.txt") as f: words_list = {word.removesuffix("n") for word in f} with open("neg.csv") as g: for tweete in g: for word in tweete.split(): if word not in words_list: print(word) and the output is like this: gfg best gfg I am …

Total answers: 2