Want to get involved? We're always looking for ideas and content for Weekly Challenges.
SUBMIT YOUR IDEAFelt very intimidating to start but just clicking around I ended up learning about a brilliant tool I had no idea existed before!
This one is tough - I'm not 100% sure if this is correct, but I decided to do it in Python.
import pandas as pd
import random
import matplotlib.pyplot as plt
class Alteryx:
def __init__(self, excel_fp) -> None:
# File path for the Excel workbook that contains the First name, Last name, and Email address
self.excel_fp = excel_fp
# Store the randomly generated numbers
self.numbers = list()
# Average
self.mean = 70
# Standard deviation
self.sigma = 5
def read_excel(self) -> None:
"""
DataFrame that has:
1. First name
2. Last name
3. Email address
"""
self.df = pd.read_excel(io=self.excel_fp, header=0, keep_default_na=True)
def gaussian(self) -> None:
for _ in range(len(self.df['First'])):
temp = random.gauss(mu=self.mean, sigma=self.sigma)
self.numbers.append(temp)
def append_and_save_scores(self) -> None:
# Add the columns with the scores to the DataFrame
self.df['scores'] = self.numbers
# Save the DataFrame to an Excel workbook
self.df.to_excel('./main stuff/output.xlsx', index=False)
def plot(self) -> None:
# Labels
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax1.set_ylabel('Count')
ax1.set_xlabel('Number')
ax1.set_title('Alteryx Weekly Challenge #141')
# Histogram
plt.hist(x=self.numbers, bins=50)
# Show the histogram
plt.show()
# Instantiate class and call functions
if __name__ == '__main__':
c = Alteryx(excel_fp='./main stuff/test_input.xlsx')
c.read_excel()
c.gaussian()
c.append_and_save_scores()
c.plot()
The result:
Simulation Sampling tool is key