ModuleNotFoundError for matplotlib and pandas in Visual Studio Code

Viewed 5751

When I import matplotlib.pylot as plt and pandas as pd in my code and run it, I get the error in the terminal saying "ModuleNotFoundError: No module named 'matplotlib'" and "ModuleNotFoundError: No module named 'pandas'" (pandas error will occur when I have the import pandas module on the first line of my code). When I hover over the two modules, the message "Import 'matplotlib.pyplot' could not be resolved from source" and "Import 'pandas' could not be resolved from source" will appear. How can I fix these problems so that my code will properly run and not receive those error messages?

import matplotlib.pyplot as plt
import pandas as pd

temp_data = pd.read_csv("temperature_data.csv", header=0) 

plt.plot(temp_data['Year'], temp_data['Anomaly'], color='gray')
plt.ylabel('Temperature Anomalies in Celsius')
plt.xlabel('Years')
plt.title('Change in Temperatures')
plt.show()
0 Answers
Related