jeudi 25 février 2021

Python Script for generating random numbers within a given range every 5 minutes interval with timestamp

I'm looking for a script that loops forever and keep generating random numbers every 5 minutes with timestamp(e.g. the excel file will have two columns [timestamp = jan 5 14:00][value = 120]) and insert it into an excel file. This program will run forever and keep populating the excel file, and when re-run, it continues to populate from the last stopped row. I have a program to generate a random number for a certain number of times and store them into excel. But the value is always replaced. I'm not sure how to do the rest. Please help. Thank you.

import pandas as pd
import random
from xlsxwriter import*


def Rand(start, end, num): 
    result = [] 
  
    for j in range(num): 
        result.append(random.randint(start, end)) 
  
    return result 
  
num = 100
start = 100
end = 151
random = (Rand(start, end, num))



df = pd.DataFrame.from_dict({'Random No':random})
df.to_excel('test2.xlsx', header=True, index=False)

enter image description here




Aucun commentaire:

Enregistrer un commentaire