mardi 24 avril 2018

Generating random numbers with Only integers, not floats

I have created a python script where I have 4 empty lists, and the code creates a random numbers on those lists, and in the end, it saves it as an Excel file. The issue is there that it creates numbers with floats, and I only want integers! Could somebody help me?

Here is my code:

import numpy as np
import openpyxl
import random

from openpyxl import Workbook

# Create workbook object
wb = openpyxl.Workbook()
sheet = wb.get_active_sheet()

sheet.title = 'Sheet #1'



# Generate data

Timestamp = [0, 1, 2, 3, 4, 5, 6, 7,8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]

Subtotal_vest = []

Subtotal_NorthEast = []

Subtotal_south = []

Others = []



for i in Timestamp:
    Subtotal_vest.append(random.gauss(3640, 25)),
    Subtotal_NorthEast.append(random.gauss(3832, 25)),
    Subtotal_south.append(random.gauss(2592, 25)),
    Others.append(random.gauss(1216, 25)),







#y = x * x

# Add titles in the first row of each column
sheet.cell(row=1, column=1).value = 'Timestamp'
sheet.cell(row=1, column=2).value = 'Vest'
sheet.cell(row=1, column=3).value = 'North east'
sheet.cell(row=1, column=4).value = 'South'
sheet.cell(row=1, column=5).value = 'Others'

#sheet.cell(row=1, column=2).value = 'Y values'

# Loop to set the value of each cell

for inputs in range(0, len(Timestamp)):
    sheet.cell(row=inputs + 2, column=1).value = Timestamp[inputs]
    sheet.cell(row=inputs + 2, column=2).value = Subtotal_vest[inputs]
    sheet.cell(row=inputs + 2, column=3).value = Subtotal_NorthEast[inputs]
    sheet.cell(row=inputs + 2, column=4).value = Subtotal_south[inputs]
    sheet.cell(row=inputs + 2, column=5).value = Others[inputs]



# Finally, save the file and give it a name
wb.save('Excel/Matrix.xlsx')




Aucun commentaire:

Enregistrer un commentaire