Advertisement
UF6

Improved Bar Graph That Can Take Mean Values And Columns

UF6
Nov 8th, 2023
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 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. # Create a bar plot for the mean values
  24. plt.figure(figsize=(10, 6))
  25. plt.bar(summary_statistics.index, summary_statistics['mean'])
  26. plt.xlabel('Columns')
  27. plt.ylabel('Mean')
  28. plt.title('Mean Values for Selected Columns')
  29. plt.xticks(rotation=45)
  30. plt.tight_layout()
  31.  
  32. # Show the plot
  33. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement