Advertisement
UF6

Bar Graph for STD, MEAN, 25% ,50%, 75%, and MAX

UF6
Nov 8th, 2023
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | Source Code | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3.  
  4. # Replace 'B5 segmentSummary (1).csv' with the actual CSV file path
  5. file_path = 'B5 segmentSummary (1).csv'
  6.  
  7. # Define the range of column positions you want to analyze (columns 6 through 10)
  8. start_column_position = 6  # Corresponds to column 6
  9. end_column_position = 9    # Corresponds to column 10
  10.  
  11. # Read the CSV file into a Pandas DataFrame
  12. df = pd.read_csv(file_path)
  13.  
  14. # Select columns 6 through 10 for analysis
  15. selected_columns = df.iloc[:, start_column_position:end_column_position + 1]
  16.  
  17. # Calculate summary statistics for the selected columns
  18. summary_statistics = selected_columns.describe()
  19.  
  20. # Transpose the summary statistics for plotting
  21. summary_statistics = summary_statistics.T
  22.  
  23. # Extract the statistics you want to plot
  24. statistics_to_plot = ['mean', 'std', 'min', '25%', '50%', '75%', 'max']
  25.  
  26. # Create a grouped bar plot for the selected statistics
  27. plt.figure(figsize=(12, 6))
  28. x = range(len(summary_statistics.index))
  29. bar_width = 0.15
  30.  
  31. for i, statistic in enumerate(statistics_to_plot):
  32.     plt.bar(
  33.         [pos + i * bar_width for pos in x],
  34.         summary_statistics[statistic],
  35.         width=bar_width,
  36.         label=statistic
  37.     )
  38.  
  39. plt.xlabel('Columns')
  40. plt.ylabel('Values')
  41. plt.title('Summary Statistics for Selected Columns')
  42. plt.xticks([pos + 3 * bar_width for pos in x], summary_statistics.index, rotation=45)
  43. plt.legend()
  44. plt.tight_layout()
  45.  
  46. # Show the plot
  47. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement