loops

Loop through dataframe one by one (pandas)

不打扰是莪最后的温柔 提交于 2020-08-02 04:15:17
问题 Let's say we have a dataframe with columns A, B and C: df = pd.DataFrame(columns =('A','B','C'), index=range(1)) The columns holds three rows of numeric values: 0 A B C 1 2.1 1.8 1.6 2 2.01 1.81 1.58 3 1.9 1.84 1.52 How does one loop through every row from 1 to 3 and then execute an if statement including add some variables: if B1 > 1.5 calc_temp = A1*10 calc_temp01 = C1*-10 if B2 > 1.5 calc_temp = A2*10 calc_temp01 = C2*-10 if B3 >1.5 calc_temp = A3*10 calc_temp01 = C3*-10 Is above even

Loop through dataframe one by one (pandas)

北慕城南 提交于 2020-08-02 04:14:12
问题 Let's say we have a dataframe with columns A, B and C: df = pd.DataFrame(columns =('A','B','C'), index=range(1)) The columns holds three rows of numeric values: 0 A B C 1 2.1 1.8 1.6 2 2.01 1.81 1.58 3 1.9 1.84 1.52 How does one loop through every row from 1 to 3 and then execute an if statement including add some variables: if B1 > 1.5 calc_temp = A1*10 calc_temp01 = C1*-10 if B2 > 1.5 calc_temp = A2*10 calc_temp01 = C2*-10 if B3 >1.5 calc_temp = A3*10 calc_temp01 = C3*-10 Is above even

How to recursively iterate through files in PHP?

人盡茶涼 提交于 2020-08-01 09:49:24
问题 I have set up a basic script that is posting an array of paths to find template files inside them; currently it's only searching two levels deep and I'm having some troubles getting my head around the logic for an extensive loop to iterate all child directories until the length is 0. So if I have a structure like this: ./components ./components/template.html ./components/template2.html ./components/side/template.html ./components/side/template2.html ./components/side/second/template.html .

How to recursively iterate through files in PHP?

僤鯓⒐⒋嵵緔 提交于 2020-08-01 09:49:05
问题 I have set up a basic script that is posting an array of paths to find template files inside them; currently it's only searching two levels deep and I'm having some troubles getting my head around the logic for an extensive loop to iterate all child directories until the length is 0. So if I have a structure like this: ./components ./components/template.html ./components/template2.html ./components/side/template.html ./components/side/template2.html ./components/side/second/template.html .

How to make a new list of first elements from existing list of lists

瘦欲@ 提交于 2020-07-27 23:26:55
问题 I have a list below. I need to use it to create a new list with only country names. How do I loop x in order to have a list of country names? x = [["UK", "LONDON", "EUROPE"], ["US", "WASHINGTON", "AMERICA"], ["EG", "CAIRO", "AFRICA"], ["JP", "TOKYO", "ASIA"]] The outcome should look like UK US EG JP 回答1: You have two ways Using a for loop countries = [] for e in x: countries.append(e[0]) or with list comprehensions, which would be in most cases the better option countries = [e[0] for e in x]

How to make a new list of first elements from existing list of lists

不想你离开。 提交于 2020-07-27 23:26:32
问题 I have a list below. I need to use it to create a new list with only country names. How do I loop x in order to have a list of country names? x = [["UK", "LONDON", "EUROPE"], ["US", "WASHINGTON", "AMERICA"], ["EG", "CAIRO", "AFRICA"], ["JP", "TOKYO", "ASIA"]] The outcome should look like UK US EG JP 回答1: You have two ways Using a for loop countries = [] for e in x: countries.append(e[0]) or with list comprehensions, which would be in most cases the better option countries = [e[0] for e in x]

Creating classes inside a loop Python

拜拜、爱过 提交于 2020-07-23 10:36:27
问题 I'm working on a Python project and I want to do something like the next example, but is incorrect. I need some help, please! names = ['name1', 'name2'] for name in names: class name: [statements] Thank you! 回答1: The class statement requires a hard-coded class name. You can use the type function, however, to create such dynamic classes. names = ['name1', 'name2'] class_dict = {} for name in names: # statements to prepare d class_dict[name] = type(name, (object,), d) Here, d is a dictionary

Creating classes inside a loop Python

北慕城南 提交于 2020-07-23 10:34:46
问题 I'm working on a Python project and I want to do something like the next example, but is incorrect. I need some help, please! names = ['name1', 'name2'] for name in names: class name: [statements] Thank you! 回答1: The class statement requires a hard-coded class name. You can use the type function, however, to create such dynamic classes. names = ['name1', 'name2'] class_dict = {} for name in names: # statements to prepare d class_dict[name] = type(name, (object,), d) Here, d is a dictionary

Creating classes inside a loop Python

▼魔方 西西 提交于 2020-07-23 10:33:00
问题 I'm working on a Python project and I want to do something like the next example, but is incorrect. I need some help, please! names = ['name1', 'name2'] for name in names: class name: [statements] Thank you! 回答1: The class statement requires a hard-coded class name. You can use the type function, however, to create such dynamic classes. names = ['name1', 'name2'] class_dict = {} for name in names: # statements to prepare d class_dict[name] = type(name, (object,), d) Here, d is a dictionary

powershell : increment foreach loop datas from a csvfile to an xml output file

陌路散爱 提交于 2020-07-23 07:38:07
问题 Could you help me implementing a counter in order to generate an xml file with multiple element from a csv inside? Here is the csv file UCB63_DATENUM;U6618_FILENAME;UF6E8_CANAL;U65B8_IDRP 7/8/19 22:27;457E6659_ZN_LIQRLVPR_A_V_ML.pdf;ML;1367091 9/11/19 23:03;49453878_ZN_LIQRLVPR_A_V_ML.pdf;ML;106440 9/24/19 21:04;497E585B_ZN_LIQRLVPR_A_V_CS.pdf;CS;1536658 2/12/20 22:12;58453B75_ZN_LIQRLVPR_A_V_ML.pdf;ML;1406091 and the code My return on the screen is good but as I am not calling the value, it