for-loop

I don't understand how ev_range = row[1] knows to change the strings in the second column of each row to an integer

I don't understand how ev_range = row[1] knows to change the strings in the second column of each row to an integer Question: ev_data = [[‘vehicle’, ‘range’, ‘price’], [‘Tesla Model 3 LR’, ‘310’, ‘49900’], [‘Hyundai Ioniq EV’, ‘124’, ‘30315’], [‘Chevy Bolt’, ‘238’, ‘36620’]] for row in ev_data[1:]: ev_range = row[1] ev_range = int(ev_range) row[1] = …

Total answers: 2

Create one long string from multiple lists of strings

Create one long string from multiple lists of strings Question: I am writing this back-end code to filter through a dataframe using df.query(). I have two lists from which I need to make this new string which will be passed as the query. Can anyone help me out? list1 = [‘Product == "Dress"’, ‘Product == …

Total answers: 4

How to skip one loop in a for loop?

How to skip one loop in a for loop? Question: I’m trying to make a really simple code that works sort of like wordle. It gets a random 5 letter word and asks the user to guess the word. The code will then output if a letter was in the word and if the letter …

Total answers: 1

Python/Pandas. For loop on multiple dataFrames not working correctly

Python/Pandas. For loop on multiple dataFrames not working correctly Question: I am trying to process a list of dataframes (example shows 2, reality has much more) in multiple ways using a for loop. Droping columns in the dataframe referenced in the loop works fine, however, concat doesn’t do anything inside the loop. I expect to …

Total answers: 1

How to combine files in python 3 – with open() as: NOT working

How to combine files in python 3 – with open() as: NOT working Question: I am trying to combine the content of all .txt files in a directory one level above the directory where the .py file below is stored. import os def main(): # Get list of files stored in a dir above this …

Total answers: 3

Problem solving without for loop,but with vectorization (pandas dataframe) considering multi condition

Problem solving without for loop,but with vectorization (pandas dataframe) considering multi condition Question: I have a dataframe like below : id = [‘A’,’A’,’A’,’A’,’A’,’B’,’B’,’B’] workcycle = [0,4,5,100,140,0,5,20] date = [‘2022-01-01′,’2022-01-01′,’2022-01-02′,’2022-02-04′,’2022-03-10′,’2022-01-01′,’2022-01-02′,’2022-02-04’] failure_type=[‘A’,’B’,None,’B’,None,’A’,None,None] repair_type=[None,None,’Repair_Type_1′,None,’Repair_Type_2′,None,’Repair_Type_1′,’Repair_Type_2′] event=[‘failure’,’failure’,’Repair’,’failure’,’Repair’,’failure’,’Repair’,’Repair’] This is dataframe about failure and repair of some machine. And there are multi failure type. There are two criteria (workcycle and date) …

Total answers: 1

having trouble with appending in nested lists in python

having trouble with appending in nested lists in python Question: I am having trouble with appending to a nested list in python. It keeps giving me a final list with double the list size it should be. When I loop through the second loop the first time it gives me an list with eleven elements …

Total answers: 1

convert each slice of a numpy file to jpeg format with for loop

convert each slice of a numpy file to jpeg format with for loop Question: I’m beginners in python I have a numpy file with the shapes of (200, 256, 256). I want to save each slice (:, 256, 256) with jpeg format. how can I do using a for loop ? Thanks in advance I …

Total answers: 1

Python : List Comprehensn with IF/ELSE statement

Python : List Comprehensn with IF/ELSE statement Question: I’m looking for an oneliner for this below logic: links (list) variable will contain = [‘**www.google.com/api/1.js**’,’**/path.js**’] url = "mysite.com" valid_links = [url + u for u in links if not urlparse(u).netloc ] This will give me only [‘mysite.com/path.js’] but not ‘www.google.com‘ in the list. I need full …

Total answers: 1