Question
################################################################################################ #Box plot code ################################################################################################ #Purpose: Create box plot for period 2 data #Name: Your name #Date: Your date import pandas as pd import matplotlib.pyplot
################################################################################################
#Box plot code
################################################################################################
#Purpose: Create box plot for period 2 data
#Name: Your name
#Date: Your date
import pandas as pd
import matplotlib.pyplot as plt
df2 = pd.read_csv("formatdata2.csv")
df2.boxplot(); plt.suptitle('Period 2 box plot')
plt.show()
################################################################################################
#Compare periods plot
################################################################################################
#Purpose: Create Celsius plot comparing period 1 and period 2
#Name: Your name
#Date: Your date
import pandas as pd
import matplotlib.pyplot as plt
df1 = pd.read_csv("formatdata.csv") #baseline data is period 1 (older)
df2 = pd.read_csv("formatdata2.csv") #data for period 2 (more recent)
plt.figure(); df1.Celsius.plot(label = 'period '); df2.Celsius.plot(label = 'period 2'); plt.legend(loc='best'); plt.suptitle('Celsius')
plt.show()
################################################################################################
#Histogram
################################################################################################
#Purpose: Create a histogram of humidity data from the second period
#Name: Your name
#Date: Your date
import pandas as pd
import matplotlib.pyplot as plt
df1 = pd.read_csv("formatdata.csv")
df2 = pd.read_csv("formatdata2.csv")
df2['Humidity'].hist(bins=10, alpha=0.5); plt.suptitle('Histogram of Humidity')
plt.show()
#name is Chris Baldwin
#Date is December 29 2020
Using this code
#_*_ coding: utf-8 _*_
"""
Created on Friday December 5 2020
@author: Christopher
"""
#Purpose: Extract temperature, humidity data from weather database into CSV file
#Name: Chris Baldwin
#Date: Friday December 18 2020
# Run BuildWeatherDB.py to build weather database before running this program
import sqlite3
#convert Celsius temperature to Fahrenheit
def convertCtoF(tempC):
return (tempC*9.0/5.0) + 32.0
#file names for database and output file
dbFile = "weather.db"
output_file_name='formatdata2.csv'
#connect to and query weather database and
dbFile = "weather.db"
conn = sqlite3.connect(dbFile)
#create cursor to execute SQL commands
cur = conn.cursor()
selectCmd = """ SELECT temperature, relativeHumidity FROM observations
ORDER BY timestamp; """
cur.execute(selectCmd)
################################################################################################ #Scatter plot ################################################################################################ #Purpose: Create scatter plot of humidity for period 1. Can replace df1 to df2 to display second period data #Name: Your name #Date: Your date import pandas as pd import matplotlib.pyplot as plt df1 = pd.read_csv("formatdata.csv") df2 = pd.read_csv("formatdata2.csv") plt.scatter(df1.index.values,df1['Humidity']); plt.suptitle('Humidity') plt.show()
allRows = cur.fetchall()
#limit the number of rows output to half
rowCount = len(allRows)//2 # double slash does integer division
rows = allRows[rowCount:]
#write data to output file
with open(output_file_name,"w+") as outf:
outf.write('Celsius,Fahrenheit,Humidity')
outf.write(' ')
for row in rows:
tempC = row[0]
if tempC is None: #handle missing temperature value
outf.write(',,')
else:
tempF = convertCtoF(tempC)
outf.write(str(tempC)+',')
outf.write(str(tempF)+',')
humidity = row[1]
if humidity is None: #handle missing humidity value
outf.write(' ')
else:
outf.write(str(humidity)+' ') #print data to file separated by commas
################################################################################################ #Box plot code ################################################################################################ #Purpose: Create box plot for period 2 data #Name: Your name #Date: Your date import pandas as pd import matplotlib.pyplot as plt df2 = pd.read_csv("formatdata2.csv") df2.boxplot(); plt.suptitle('Period 2 box plot') plt.show() ################################################################################################ #Compare periods plot ################################################################################################ #Purpose: Create Celsius plot comparing period 1 and period 2 #Name: Your name #Date: Your date import pandas as pd import matplotlib.pyplot as plt df1 = pd.read_csv("formatdata.csv") #baseline data is period 1 (older) df2 = pd.read_csv("formatdata2.csv") #data for period 2 (more recent) plt.figure(); df1.Celsius.plot(label = 'period '); df2.Celsius.plot(label = 'period 2'); plt.legend(loc='best'); plt.suptitle('Celsius') plt.show() ################################################################################################ #Histogram ################################################################################################ #Purpose: Create a histogram of humidity data from the second period #Name: Your name #Date: Your date import pandas as pd import matplotlib.pyplot as plt df1 = pd.read_csv("formatdata.csv") df2 = pd.read_csv("formatdata2.csv") df2['Humidity'].hist(bins=10, alpha=0.5); plt.suptitle('Histogram of Humidity') plt.show()
################################################################################################
#Scatter plot
################################################################################################
#Purpose: Create scatter plot of humidity for period 1. Can replace df1 to df2 to display second period data
#Name: Your name
#Date: Your date
import pandas as pd
import matplotlib.pyplot as plt
df1 = pd.read_csv("formatdata.csv")
df2 = pd.read_csv("formatdata2.csv")
plt.scatter(df1.index.values,df1['Humidity']); plt.suptitle('Humidity')
plt.show()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started