I have two possible lists, one is the name and the second is the age. my function needs to return copies of these lists such that they are both sorted in order of age (descending order) (ie the names of employees in the lst1 are also required to be ordered according to their ages in lst2). If two or more
Tag: loops
Including the last value in a range loop Python 3
I am having issues trying to get my code to print the last value of the range when I am running a loop. Here is the problem I was given with my code at the end: Here is the output I receive: A B C D E F G H I J K L M N O P Q R
Fastest way to get values from dictionary to another dictionary in python without using if?
I need to find a way to get values from one dictionary to another, bases on key name match without using two loops if statement. Main goal is to make it run more efficiently since it’s a part of a larger code and run on multiple threads. If you can keep the dictionary structure it would help The second
How do I make a program keep repeating until I input a specific data that stops it?
I’m trying to make a program in python so that when I input a number from 1 to 10, a specific set of program goes on and asks for another number from 1 to 10 and runs another program, until I enter 0(zero) and the program stops. So my guess was using a while loop but it didn’t quite work
How to find the maximum number in python repeatedly from a group of numbers
I have a numpy array like below: In this data there are 20 numbers and they are divided in 4 groups with 5 numbers in each group. so for ex. I want to find out the maximum number from each group and store them in a list. Like: I am very new to python please help. Answer try by splitting
Check column for variable and get value from another column in matched row
How can I get the values of one column in a csv-file by matching attributes in another column? CSV-file would look like that: I only want to get the values of column 3, if they have the value “car” in column 2. I also do not want them to be added but rather have them printed in a list, or
Is it possible to get binary count from Counter() Python
Using Counter(), I want to do a binary count of variables in a list. So instead of getting the count for each variable, I would simply like to have a Counter() variable, in which all values are one. So for a given list: I want the output to be: Instead of: I am aware that I could loop through the
How do I create a linear regression model for a file that has about 500 columns as y variables? Working with Python
This code manually selects a column from the y table and then joins it to the X table. The program then performs linear regression. Any idea how to do this for every single column from the y table? Answer You can regress multiple y’s on the same X’s at the same time. Something like this should work produces The first
How can I avoid for-loops using pandas?
Would love to know how to optimize this code without using for-loops, if it’s possible. What I’m trying to do is to categorize all the values in series df[‘Состояние’] looking at key words in lists list_rep and list_dem one by one. Thank you! Answer Use Series.str.lower fiirst, then Series.str.contains with join by | for regex OR and set new values
What is best way to loop through Pandas dataframe employing a sequentially counted value in each row where condition is true?
Business Problem: For each row in a Pandas data frame where condition is true, set value in a column. When successive rows meet condition, then increase the value by one. The end goal is to create a column containing integers (e.g., 1, 2, 3, 4, … , n) upon which a pivot table can be made. As a side note,