Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Excercise_6.py
Original file line number Diff line number Diff line change
@@ -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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job


# 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()


Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job

Binary file added Plot_Method 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Plot_Method 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions six.txt
Original file line number Diff line number Diff line change
@@ -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)


Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job