fork download
  1. import numpy as np
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. from scipy import stats
  5.  
  6. np.random.seed(0)
  7. data = np.random.randint(10, 60, size=100)
  8. data_series = pd.Series(data)
  9.  
  10. mean_value = data_series.mean()
  11. median_value = data_series.median()
  12. mode_value = data_series.mode()[0] # Get the first mode
  13.  
  14. print(f"Mean: {mean_value}")
  15. print(f"Median: {median_value}")
  16. print(f"Mode: {mode_value}")
  17.  
  18. plt.figure(figsize=(10, 6))
  19. plt.hist(data_series, bins=15, color='lightblue', alpha=0.7, edgecolor='black')
  20.  
  21. # Correcting the f-string syntax by keeping it on a single line
  22. plt.axvline(mean_value, color='red', linestyle='dashed', linewidth=2, label=f'Mean: {mean_value:.2f}')
  23. plt.axvline(median_value, color='green', linestyle='dashed', linewidth=2, label=f'Median: {median_value:.2f}')
  24. plt.axvline(mode_value, color='blue', linestyle='dashed', linewidth=2, label=f'Mode: {mode_value:.2f}')
  25.  
  26. plt.title('Histogram of Ages with Mean, Median, and Mode')
  27. plt.xlabel('Age')
  28. plt.ylabel('Frequency')
  29. plt.legend()
  30. plt.grid(axis='y', alpha=0.75)
  31. plt.show()
  32.  
Success #stdin #stdout 3.58s 114288KB
stdin
Standard input is empty
stdout
Mean: 32.5
Median: 30.5
Mode: 10