loops

For loop keeps iterating over first piece of data in list

限于喜欢 提交于 2020-04-30 06:32:20
问题 This code scrapes the HTML table from https://www.asx.com.au/asx/statistics/prevBusDayAnns.do and downloads PDF files for specific ASX Codes and Headlines. When the for loop iterates over the ASX Codes found in 'data', it iterates over the first ASX Code five times which creates five duplicate of the same PDF. For example, in the code below there would be five copies of TWD. The amount of times the for loop iterates over the first ASX code is equal to the amount of ASX Codes in 'data'. For

Generating random number with different digits

我只是一个虾纸丫 提交于 2020-04-30 05:21:31
问题 So I need to write a program which generates random numbers from 100 to 999, and the tricky part is that the digits in the number can't be the same. For example: 222 , 212 and so on are not allowed. So far, I have this: import random a = int (random.randint(1,9)) <-- first digit b = int (random.randint(0,9)) <-- second digit c = int (random.randint(0,9)) <-- third digit if (a != b and a != b and b != c): print a,b,c As you can see, I generate all three digits separately. I think it's easier

Generating random number with different digits

岁酱吖の 提交于 2020-04-30 05:20:10
问题 So I need to write a program which generates random numbers from 100 to 999, and the tricky part is that the digits in the number can't be the same. For example: 222 , 212 and so on are not allowed. So far, I have this: import random a = int (random.randint(1,9)) <-- first digit b = int (random.randint(0,9)) <-- second digit c = int (random.randint(0,9)) <-- third digit if (a != b and a != b and b != c): print a,b,c As you can see, I generate all three digits separately. I think it's easier

How do I extract table data in pairs using BeautifulSoup?

╄→尐↘猪︶ㄣ 提交于 2020-04-29 11:58:30
问题 My data sample : <table id = "history"> <tr class = "printCol"> <td class="name">Google</td><td class="date">07/11/2001</td><td class="state"> <span>CA</span> </td> </tr> <tr class = "printCol"> <td class="name">Apple</td><td class="date">27/08/2001</td> </tr> <tr class = "printCol"> <td class="name">Microsoft</td><td class="date">01/11/1991</td> </tr> </table> Beautifulsoup code : table = soup.find("table", id = "history") rows = table.findAll('tr') for tr in rows: cols = tr.findAll('td')

How to Split Python list every Nth element

耗尽温柔 提交于 2020-04-29 07:04:09
问题 What I am trying to do is pretty simple, but I couldn't find how to do it. Starting with 1st element, put every 4th element into a new list. Repeat with the 2nd, 3rd, and 4th elements. From: list = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b'] To: list1 = ['1', '5', '9'] list2 = ['2', '6', 'a'] list3 = ['3', '7', 'b'] list4 = ['4', '9'] In other words, I need to know how to: Get the Nth element from a list (in a loop) Store it in new arrays Repeat 回答1: The specific solution is to

How to Split Python list every Nth element

只谈情不闲聊 提交于 2020-04-29 07:04:03
问题 What I am trying to do is pretty simple, but I couldn't find how to do it. Starting with 1st element, put every 4th element into a new list. Repeat with the 2nd, 3rd, and 4th elements. From: list = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b'] To: list1 = ['1', '5', '9'] list2 = ['2', '6', 'a'] list3 = ['3', '7', 'b'] list4 = ['4', '9'] In other words, I need to know how to: Get the Nth element from a list (in a loop) Store it in new arrays Repeat 回答1: The specific solution is to

create new rows based the values of one of the column in pandas or numpy

岁酱吖の 提交于 2020-04-28 20:25:28
问题 I have a data frame as shown below. which is doctors appointment data. B_ID No_Show Session slot_num Cumulative_no_show 1 0.4 S1 1 0.4 2 0.3 S1 2 0.7 3 0.8 S1 3 1.5 4 0.3 S1 4 1.8 5 0.6 S1 5 2.4 6 0.8 S1 6 3.2 7 0.9 S1 7 4.1 8 0.4 S1 8 4.5 9 0.6 S1 9 5.1 12 0.9 S2 1 0.9 13 0.5 S2 2 1.4 14 0.3 S2 3 1.7 15 0.7 S2 4 2.4 20 0.7 S2 5 3.1 16 0.6 S2 6 3.7 17 0.8 S2 7 4.5 19 0.3 S2 8 4.8 From the above when ever u_cumulative > 0.8 create a new row just below that with No_Show = 0.0 and its Session

Iterating over different data frames using an iterator

假如想象 提交于 2020-04-21 17:27:11
问题 Suppose I have n number of data frames df_1 , df_2 , df_3 , ... df_n , containing respectively columns named SPEED1 , SPEED2 , SPEED3 , ..., SPEEDn , for instance: import numpy as np df_1 = pd.DataFrame({'SPEED1':np.random.uniform(0,600,100)}) df_2 = pd.DataFrame({'SPEED2':np.random.uniform(0,600,100)}) and I want to make the same changes to all of the data frames. How do I do so by defining a function on similar lines? def modify(df,nr): df_invalid_nr=df_nr[df_nr['SPEED'+str(nr)]>500] df

How do I solve this Java question of printing a table using a for loop?

穿精又带淫゛_ 提交于 2020-04-18 06:33:41
问题 (Print a table) Write a program that displays the following table. Cast floating point numbers into integers. a b pow(a, b) 1 2 1 2 3 8 3 4 81 4 5 1024 5 6 15625 I am having trouble conceptualizing how I can make this code simpler using loops. public class Exercise_02_eighteen { public static void main(String[] args) { float a, b; System.out.println("a b pow(a, b)"); a = 1; b = 2; System.out.println((int)a + " " + (int)b + " " + (int)Math.pow(a, b)); a++; b++; System.out.println((int)a + " "

How do I solve this Java question of printing a table using a for loop?

允我心安 提交于 2020-04-18 06:33:08
问题 (Print a table) Write a program that displays the following table. Cast floating point numbers into integers. a b pow(a, b) 1 2 1 2 3 8 3 4 81 4 5 1024 5 6 15625 I am having trouble conceptualizing how I can make this code simpler using loops. public class Exercise_02_eighteen { public static void main(String[] args) { float a, b; System.out.println("a b pow(a, b)"); a = 1; b = 2; System.out.println((int)a + " " + (int)b + " " + (int)Math.pow(a, b)); a++; b++; System.out.println((int)a + " "