Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Random Numbers in Excel into percentage

Hi my code works fine but is there any way to print how many times numbers 1-6 were said into a percentage

I haven’t tried anything yet.

import pandas as pd
import random

data = [random.randint(0,6) for _ in range(10)]

df = pd.DataFrame(data)

print(df)

df.to_excel(r'H:\Grade10\Cs\Mir Hussain 12.00.00 3.xlsx', index=False)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

So from your data you could do:

import random
from collections import Counter


data = [random.randint(0,6) for _ in range(10)]
total_data = [data]

frequency = Counter(data)
number_elements = len(data)

total_data.append(list((frequency[item] / number_elements)*100 if item != 0 else '' for item in total_data[0]))

df = pd.DataFrame(total_data)

print(df)

df.to_excel(r'H:\Grade10\Cs\Mir Hussain 12.00.00 3.xlsx', index=False)

Item frequency count in Python

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading