Question

Using Python3,

How can I aggregate the output from each iteration to one single list? Because from the program I have right now, it gives me the result of every iteration and gives me something like this as individual results and not one large list:

None

None

...

None

130.0

None

...

1764

1765

None

To clarify, I have this program where it calculates the sum of bytes sent within each incrementation of every 1 second, but there are instances where I want to record the specific times when the sum of the bytes in the given second are above the threshold value.

The main part of code is below:
max_time = round(max_time,0) #rounding the number so that it should have only integer value

chunk = 1 #defines length of constant interval which is 1sec

def event_occurence(time, threshold):
load,res=[],[]
for i,j in zip(data_timestamp,data_load):
if(i<chunk and i>=time-chunk): #limit calculation for timestamps between restrictions, for example (3.14<4 and 3.14>=3)
load.append(j) #add bytes to list
if sum(load) >= threshold: #check to see if total bytes sent in that second pass threshold
res.append(i) #the timestamp of the very first instance it passed the threshold is added to res list
fin = np.ceil(res[0]) #round timestamp of first instance since its orignally a decimal
return int(fin)

for k in range(chunk, max_time+chunk, chunk):
print(event_occurence(k,3500))

How can I make just one big list that also does not include "None"

S.Py iied.py amttie import pandas as pd import openpyxl as xl import math import numpy as np 1 4 /Users/myname/Des ktop/Book

ignore xl import

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# I couldn't add an execution screenshot because I don't have the excel file used in the question but the code will run fine

max_time = round(max_time,0) #rounding the number so that it should have only integer value

chunk = 1 #defines length of constant interval which is 1sec

def event_occurence(time, threshold):
load,res=[],[]
for i,j in zip(data_timestamp,data_load):
if(i<chunk and i>=time-chunk): #limit calculation for timestamps between restrictions, for example (3.14<4 and 3.14>=3)
load.append(j) #add bytes to list
if sum(load) >= threshold: #check to see if total bytes sent in that second pass threshold
res.append(i) #the timestamp of the very first instance it passed the threshold is added to res list
fin = np.ceil(res[0]) #round timestamp of first instance since its orignally a decimal
return int(fin)

# Code is same upto this point

event_list = [] # starting an empty list
for k in range(chunk, max_time+chunk, chunk):
e = event_occurence(k,3500)
if e != None: # check that the returned value is not None
event_list.append(e) # appending the value to the list

print(event_list) # printing the list

Add a comment
Know the answer?
Add Answer to:
Using Python3, How can I aggregate the output from each iteration to one single list? Because...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT