Advertisement
UF6

Gaussian Fit Case

UF6
Nov 14th, 2023
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | Source Code | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. from scipy.stats import norm
  4.  
  5. # Replace 'B5 segmentSummary (1).csv' with the actual CSV file path
  6. file_path = 'B5 segmentSummary (1).csv'
  7.  
  8. # Read the CSV file into a Pandas DataFrame
  9. df = pd.read_csv(file_path)
  10.  
  11. # Calculate summary statistics for the 'cases' column
  12. cases_summary = df['Slide name'].describe()
  13.  
  14. # Print summary statistics for 'cases' column
  15. print("Summary Statistics for 'Slide name' column:")
  16. print(cases_summary)
  17.  
  18. # Define the range of column positions you want to analyze (columns 6 through 9)
  19. start_column_position = 6  # Corresponds to column 6
  20. end_column_position = 9   # Corresponds to column 9
  21.  
  22. # Iterate through each numerical column and create a separate figure for Gaussian distribution
  23. for i in range(start_column_position, end_column_position + 1):
  24.     col = df.columns[i]
  25.    
  26.     # Skip 'cases' column
  27.     if col == 'Slide name':
  28.         continue
  29.    
  30.     plt.figure(figsize=(8, 6))
  31.    
  32.     # Plot Gaussian distribution
  33.     target_column = df.iloc[:, i]
  34.     mean = target_column.mean()
  35.     std_dev = target_column.std()
  36.    
  37.     # Generate data for the Gaussian distribution
  38.     x_range = target_column.dropna().values
  39.     fitted_data = norm.pdf(x_range, mean, std_dev)
  40.    
  41.     # Plot the Gaussian distribution
  42.     plt.plot(x_range, fitted_data, 'b-', label='Fitted Gaussian')
  43.    
  44.     # Plot settings
  45.     plt.hist(target_column.dropna(), bins=30, density=True, alpha=0.7, color='gray', label='Data Histogram')
  46.     plt.axvline(mean, color='red', linestyle='dashed', linewidth=2, label='Mean')
  47.     plt.xlabel('Values')
  48.     plt.ylabel('Density')
  49.     plt.title(f'Gaussian Fit for {col}')
  50.     plt.legend()
  51.    
  52.     plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement