Advertisement
GamerBhai02

4.

Jan 14th, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | Source Code | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. data = {
  4.     'Day': ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  5.     'City1': [30, 32, 33, 31, 29, 28, 30],
  6.     'City2': [25, 26, 27, 26, 25, 24, 26],
  7.     'City3': [35, 34, 33, 36, 35, 34, 36]
  8. }
  9. df = pd.DataFrame(data)
  10. print("Temperature DataFrame:")
  11. print(df)
  12. average_temperatures = df[['City1', 'City2', 'City3']].mean()
  13. highest_avg_temp_city = average_temperatures.idxmax()
  14. print("\nAverage Temperatures:")
  15. print(average_temperatures)
  16. print(f"City with the highest average temperature: {highest_avg_temp_city}")
  17. plt.figure(figsize=(10, 7))
  18. plt.plot(df['Day'], df['City1'], label='City1')
  19. plt.plot(df['Day'], df['City2'], label='City2')
  20. plt.plot(df['Day'], df['City3'], label='City3')
  21. plt.title(f"Daily Temperatures for a Week\n(Highest Average: {highest_avg_temp_city})")
  22. plt.xlabel('Day')
  23. plt.ylabel('Temperature (°C)')
  24. plt.legend()
  25. plt.grid(True)
  26. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement