From ba03d3e7db4ed0ea58d5ffb14c2b5d4a04d10294 Mon Sep 17 00:00:00 2001 From: Alicia Susi Date: Thu, 1 Nov 2018 13:42:25 -0400 Subject: [PATCH 1/3] First run through --- TutorialEx08.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 TutorialEx08.py diff --git a/TutorialEx08.py b/TutorialEx08.py new file mode 100644 index 0000000..88e06fe --- /dev/null +++ b/TutorialEx08.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Nov 1 12:54:34 2018 + +@author: Alicia +""" + +import numpy +import pandas +from plotnine import * +import matplotlib.pyplot as plt + +game=pandas.read_csv("UWvMSU_1-22-13.txt",sep="\t",header=0) + +a=ggplot(game,aes(x="time",y="score")) +a+geom_point()+coord_cartesian()+theme_classic() +plt.plot(time,UWscore,'r-',time,MSUscore,'g-') + + +#Question 2 - Guess my Number +n = numpy.random.choice(1, 99) +guess = int(numpy.random.choice("Enter an integer from 1 to 99: ")) +while n != "guess": + print + if guess < n: + print("Guess is too low") + guess = int(numpy.random.choice("Enter an integer from 1 to 99: ")) + elif guess > n: + print("Guess is too high") + guess = int(numpy.random.choice("Enter an integer from 1 to 99: ")) + else: + print("You guessed right!") + break + print \ No newline at end of file From 8d487851183b2553037ff91e5d84d359ff731da7 Mon Sep 17 00:00:00 2001 From: Alicia Susi Date: Fri, 2 Nov 2018 09:23:12 -0400 Subject: [PATCH 2/3] Updated graph with Quarters but no lines appearing --- TutorialEx08.py | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/TutorialEx08.py b/TutorialEx08.py index 88e06fe..102e0e0 100644 --- a/TutorialEx08.py +++ b/TutorialEx08.py @@ -4,31 +4,44 @@ @author: Alicia """ - -import numpy +#Question 1 import pandas -from plotnine import * import matplotlib.pyplot as plt -game=pandas.read_csv("UWvMSU_1-22-13.txt",sep="\t",header=0) - -a=ggplot(game,aes(x="time",y="score")) -a+geom_point()+coord_cartesian()+theme_classic() -plt.plot(time,UWscore,'r-',time,MSUscore,'g-') +df=pandas.read_csv("UWvMSU_1-22-13.txt",sep="\t",header=0) +print(df) +df["UWscore"]=df.loc[df["team"]=="UW","score"].cumsum() +df["MSUscore"]=df.loc[df["team"]=="MSU","score"].cumsum() +df2=df.fillna(method="ffill") +df2=df.fillna(0) +print(df2) +sorted_data=df2.sort_values('time') +print(sorted_data) +df2.loc[df2['time'].between(0,10.99),'Quarter']='First' +df2.loc[df2['time'].between(11,20.99),'Quarter']='Second' +df2.loc[df2['time'].between(21,30.99),'Quarter']='Third' +df2.loc[df2['time'].between(31,40.99),'Quarter']='Fourth' +print(df2) +plt.plot("Quarter","UWscore","r-","Quarter","MSUscore","g-") +#Question 2 - Guess My Number +import random -#Question 2 - Guess my Number -n = numpy.random.choice(1, 99) -guess = int(numpy.random.choice("Enter an integer from 1 to 99: ")) +n = random.randint(1, 100) +print('I am thinking of a number between 1 and 100.') +guess = input("Take a guess ") +guess = int(guess) while n != "guess": - print + print(guess) if guess < n: - print("Guess is too low") - guess = int(numpy.random.choice("Enter an integer from 1 to 99: ")) + print('Your guess is too low.') + guess = input("Take a guess ") + guess = int(guess) elif guess > n: - print("Guess is too high") - guess = int(numpy.random.choice("Enter an integer from 1 to 99: ")) + print('Your guess is too high.') + guess = input("Take a guess ") + guess = int(guess) else: print("You guessed right!") break - print \ No newline at end of file + print From 64c1e0d67c623bd6fdf588a2b11f8edfa790142c Mon Sep 17 00:00:00 2001 From: Alicia Susi Date: Fri, 2 Nov 2018 09:46:32 -0400 Subject: [PATCH 3/3] Final Version --- TutorialEx08.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/TutorialEx08.py b/TutorialEx08.py index 102e0e0..31011d5 100644 --- a/TutorialEx08.py +++ b/TutorialEx08.py @@ -22,7 +22,14 @@ df2.loc[df2['time'].between(21,30.99),'Quarter']='Third' df2.loc[df2['time'].between(31,40.99),'Quarter']='Fourth' print(df2) -plt.plot("Quarter","UWscore","r-","Quarter","MSUscore","g-") +plt.plot(df2["Quarter"],df2["UWscore"],"r-",df2["Quarter"],df2["MSUscore"],"g-") +plt.grid(True) +plt.axes(["First","Fourth", 0, 50]) +plt.xticks(['First','Second','Third','Fourth']) +plt.axes().spines["left"].set_position(("data",40)) +#Note that when I convert time to quarters on the x-axis it returns lines with vertical additions at each x-axis tick (I am not sure how to get rid of this) +#If I were to comment out the lines that create the 'Quarter' column and change plt.plot(df2["Quarter"],df2["UWscore"],"r-",df2["Quarter"],df2["MSUscore"],"g-") +#to plt.plot(df2["time"],df2["UWscore"],"r-",df2["time"],df2["MSUscore"],"g-") I would get a continuous graph but the x-axis would only be labeled by time and not by quarters #Question 2 - Guess My Number import random @@ -45,3 +52,6 @@ print("You guessed right!") break print + + +