I am using selenium in python and here’s a line that waits 20 seconds but sometimes still gives error as follows: How can I use try except and after except statement say goto the same line to try again?? Answer To try the same line of code untill the operation is successfull you can wrapup the line of c…
Tag: python
New column adding values of different columns with strings and numbers
I have a dataframe like this structure (in the real one there are more columns Game x, around 30, but for explaining I think it’s ok with these 2 columns): I need new columns for counting the minutes of any player in the columns “Game x” based in these conditions: Starting: means the player …
What is the difference between function and keyword/statements?
I’ve seen ‘del’ being referred to as a keyword and as a statement. Apparently, it is not considered a function: Python has a del statement (keyword) to delete objects, not a del function. https://tutorial.eyehunts.com/python/del-function-in-python-code/ I looked up the definition of a functi…
How can I figure out the average consecutive duration of “True” values in pandas df, per group?
With the following data, I think I want a column (DESIRED_DURATION_COL) to work out the duration (according to start_datetime) of consecutive Truths: project_id start_datetime diag_local_code DESIRED_DURATION_COL 1 2017-01-18 False 0 1 2019-04-14 True 0 1 2019-04-17 True 3 1 2019-04-19 False 0 1 2019-04-23 Tr…
Usage of a dictionary, Right or wrong?
I’m creating a car sales program and need to use a dictionary, I have a basic understanding of them. Would it be efficient to hold the car name as a string for the key, then store the relevant cars selling price in the values through a list? for example, Can this work? Is there a better usage for the di…
Why am I getting Syntaxerror for this while loop? [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 10 …
Substract two row values in dataframe python
Currently I have a sort of dataframe where I want to substract value from current row from the previous one. example: df = pd.Datafame([1,4,3,5,6],columns = [“time”)]) left 1 4 3 5 6 I want to iterate over these rows and store it in a list. So the list will get like this [-3,1,-2,-1]. So far I hav…
why do string.strip() function removed the character i want in some words and remove none in others
i am trying to remove the ‘n’ characters a string because when i read the lines from a file it include the ‘n’ characters!! input: output: Answer Because you are modifying the list while iterating over it, halfway through the loop, list_of_names.remove(name) is trying to remove the wro…
Fill Dataframe with values from another Dataframe (not the same column names)
I’m trying to fill a empty dataframe (OutputData) in Python with values from another dataframe (InputData). InputData has four columns (“Strike”, “DTE”, “IV”, “Pred_IV”) OutputData has as an index all unique Strikes from InputData and as Column names all u…
How to remove array from values in a dictionary
I have the following dictionary But I’d like to remove the lists so it looks like this: Is there a simple way to do this? I think I might be able to iterate through and remove the list. Thanks Answer In order to produce the required output you will need a list (set) of keys that should not be modified.