create a table that counts the number of times each integer from 1 to 100 appears in an array, including a row for the numbers between 1 to 100 that have 0 occurrences in r
main.py
import pandas as pd
# create an example arrayarr = [1, 2, 3, 3, 5, 10, 20, 20, 20]
# create a dictionary to count occurrencescount_dict = {}
for i inrange(1, 101):
count_dict[i] = arr.count(i)
# create a DataFramedf = pd.DataFrame(count_dict.items(), columns=['Number', 'Count'])
# add row for numbers with 0 occurrencesfor i inrange(1, 101):
if i notin df['Number'].values:
df = df.append({'Number': i, 'Count': 0}, ignore_index=True)
# sort the DataFrame by numberdf = df.sort_values('Number')
print(df)