diff --git a/Excercise_6.py b/Excercise_6.py new file mode 100644 index 0000000..ad27649 --- /dev/null +++ b/Excercise_6.py @@ -0,0 +1,43 @@ +# Question 1-method 1-use groupby and apply function +import pandas as pd +import matplotlib.pyplot as plt +data=pd.read_table("/Users/chenyingying/Documents/Intro_Biocom_ND_319_Tutorial6/UWvMSU_1-22-13.txt") +data['cumulative score']=data.iloc[:,2] +data['cumulative score']=data.groupby('team')['cumulative score'].apply(lambda x: x.cumsum()) +# Plot +fig,ax=plt.subplots(figsize=(8,6)) +ax.set_xlabel('Time') +ax.set_ylabel('Score') +data.groupby('team')['cumulative score'].plot(legend=True) + + +# Question 1-method 2-use for loop and if function +import pandas as pd +import matplotlib.pyplot as plt +import numpy as np +data=pd.read_table("/Users/chenyingying/Documents/Intro_Biocom_ND_319_Tutorial6/UWvMSU_1-22-13.txt") +data['UWscore']=data.iloc[:,2] +data['UWtemp']=data.iloc[:,2] +data['MSUscore']=data.iloc[:,2] +data['MSUtemp']=data.iloc[:,2] +data.loc[data['team']=='MSU','UWscore']=np.nan +data.loc[data['team']=='MSU','UWtemp']=0 +data.loc[data['team']=='UW','MSUscore']=np.nan +data.loc[data['team']=='UW','MSUtemp']=0 +data.head(n=10) +for i in range (0,len(data.index)): + if np.isnan(data.iloc[i,3])==False: + data.iloc[i,3]=data.iloc[0:i+1,4].sum() + if np.isnan(data.iloc[i,5])==False: + data.iloc[i,5]=data.iloc[0:i+1,6].sum() +# Plot +fig,ax=plt.subplots(figsize=(8,6)) +ax.set_xlabel('Time') +ax.set_ylabel('Score') +x1=data.loc[np.isfinite(data['UWscore']),'time'] +x2=data.loc[np.isfinite(data['MSUscore']),'time'] +plt.plot(x1, data['UWscore'].dropna(),label="UW") +plt.plot(x2, data['MSUscore'].dropna(),label="MSU") +plt.legend() + + diff --git a/Plot_Method 1.png b/Plot_Method 1.png new file mode 100644 index 0000000..091dd4e Binary files /dev/null and b/Plot_Method 1.png differ diff --git a/Plot_Method 2.png b/Plot_Method 2.png new file mode 100644 index 0000000..9c9a114 Binary files /dev/null and b/Plot_Method 2.png differ diff --git a/six.txt b/six.txt new file mode 100644 index 0000000..1740379 --- /dev/null +++ b/six.txt @@ -0,0 +1,38 @@ +import pandas +import numpy + +#this is a guess the number game +import random + +guessesTaken=0 + +print('Hello! What is your name?') +myName=input() + +number=random.randint(1,100) +print('Well,'+ myName +',I am thinking of a number between 1 and 100.') + +while guessesTaken < 10: + print('Take a guess') + guess=input() + guess=int(guess) + + guessesTaken=guessesTaken + 1 + + if guess < number: + print('Your guess is too low.') + + if guess > number: + print('Your guess is too high.') + + if guess == number: + guessesTaken= str(guessesTaken) + print('Good job,' + myName +'!You guessed my number in' + guessesTaken +'guesses!') + +if guess != number: + number= str(number) + print('Nope. The number I was thinking of was ' +number) + + + +