Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Iterator
#1
HI,

I am new at Python and learning how to code. I am stuck at solving a task given to me. i was able to solve some parts of the problem but got stuck with iterator and can not find any help online(or i didn't understand how to use iterator. I need to run the code below multiple times to create standard deviation plot. i need help on running the code and retrieving the information to be used to generate the plot.

Thank you in advance

Code:
import numpy as np
import pandas as pd
df = pd.read_csv('mosquitos_data.csv')
data = np.array(df.Response)
np.random.shuffle(data)
array_b = data[:25]
array_w = data[:18]
water = array_w.mean()
beer = array_b.mean()
a = water - beer
a
Reply
#2
Hello, please post your code in Python code tags, you can find help here:
https://python-forum.io/misc.php?action=help&hid=25

By iterator you mean looping through the code several times? Did you try with for loop or while loop?
https://www.learnpython.org/en/Loops
Reply
#3
Iterators are a bit more advanced concept than a loop, but here's a simple explanation of them.

You probably want just a simple loop. If you know how many points there are in the plot, you can use a for-loop. Otherwise, a while-loop with a break condition.

for instance in number-of-times:
    // do stuff

incrementer = initial value
while condition is True:
    if incrementer has reached threshold value:
        break
    //do stuff
    incrementer += 1
Reply
#4
Thank you for your help. I was able to use the for loop.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020