In: Computer Science
I have an excel file imported into canopy (python) using import pandas as pd. The excel file has headers titled:
datetime | created_at | PM25 | temperatureF | dewpointF | humidityPCNT | windMPH | wind_speedMPH | wind_gustsMPH | pressureIN | precipIN |
these column headers all have thousands of data numbers under them. How could i find the average of all of the numbers in each column and plot them on 1 graph (line graph or scatter plot) Thank you.(please comment out your code)
Here is the code for the problem, I have omitted the date and
created at columns on purpose because taking an average of dates do
not make any sense.
I have used pyplot to plot the graph and pandas to import the excel
file.
Here is the sample table that I used
In case you run the exact same code, I provided, remove the date
and created at the column, because this code considers the plot
without that.
if you liked the answer please upvote, and in case of any comments please ask in comments i will surely help.
Code:
#import panda and pyplot
import pandas as pd
import matplotlib.pyplot as plt
# read the excel file from the location you have stored it
into
df = pd.read_excel (r'C:\Users\Public\tempData.xlsx')
# extract the name of the headings/parameters
x = list(df.columns.values)
# extract the mean of the data
y = list(df.mean())
# Code to plot the diagram
plt.figure(figsize=(9,9)) # this changes the size of the
graph
# plot the graph
plt.plot(x, y,linewidth=2.0)
#set the title
plt.title('LinePlot of the given Data')
# set the x and y labels
plt.xlabel('Parameters')
plt.ylabel('Average Values')
plt.show()