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)
>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