Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import matplotlib.pyplot as plt
- data = {
- 'Day': ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
- 'City1': [30, 32, 33, 31, 29, 28, 30],
- 'City2': [25, 26, 27, 26, 25, 24, 26],
- 'City3': [35, 34, 33, 36, 35, 34, 36]
- }
- df = pd.DataFrame(data)
- print("Temperature DataFrame:")
- print(df)
- average_temperatures = df[['City1', 'City2', 'City3']].mean()
- highest_avg_temp_city = average_temperatures.idxmax()
- print("\nAverage Temperatures:")
- print(average_temperatures)
- print(f"City with the highest average temperature: {highest_avg_temp_city}")
- plt.figure(figsize=(10, 7))
- plt.plot(df['Day'], df['City1'], label='City1')
- plt.plot(df['Day'], df['City2'], label='City2')
- plt.plot(df['Day'], df['City3'], label='City3')
- plt.title(f"Daily Temperatures for a Week\n(Highest Average: {highest_avg_temp_city})")
- plt.xlabel('Day')
- plt.ylabel('Temperature (°C)')
- plt.legend()
- plt.grid(True)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement