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
47 changes: 47 additions & 0 deletions EX6_Answers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 11 23:37:13 2018

@author: Rachel R
"""

pwd
cd desktop
cd data-shell
ls
cd IBC_EX6

#Question 1
import pandas as pd
iris = pd.read_csv("/Users/Rachel R/Desktop/data-shell/IBC_EX6/iris.csv")
n = 5
head = iris[0:n]
print(head)

#Question 2
#Print the last 2 rows and last 2 columns of iris.csv to the python terminal
tail = iris.iloc[148:150, 3:5]
print(tail)

#Get the number of observations for each species included in the dataset
observations = iris["Species"].value_counts()
print(observations)

#Get rows with Sepal.Width > 3.5
Sepalwidth = iris.loc[iris['Sepal.Width'] > 3.5]
print(Sepalwidth)

#Write the data for the species setosa to a comma delimited file
setosa = iris[iris["Species"]=="setosa"]
setosa.to_csv("setosa.csv")
import pandas
pandas.read_csv("setosa.csv")

#Calculate mean, min, max, of Petal.Length for observations from virginica
import numpy
Virginica = iris[iris['Species']=='virginica']['Petal.Length']
maxval, minval, meanval = numpy.max(Virginica), numpy.min(Virginica), numpy.mean(Virginica)

print('maximum value', maxval)
print('minimum value', minval)
print('mean value', meanval)
35 changes: 35 additions & 0 deletions EX7_answers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 12 11:11:34 2018

@author: Rachel R
"""
# Question 1
import pandas as pd
irisdata = pd.read_csv("/Users/Rachel R/Desktop/data-shell/IBC_EX6/iris.csv")

def cut_sect(file):
cut_section = file.iloc[::2]
return cut_section

print cut_sect(irisdata)

# Question 2
#Return the number of observations for a given species included in the data set
def species_cut():
observations = irisdata["Species"].value_counts()
return observations
print species_cut()

#Return a dataframe for flowers with Sepal.Width greater than a given value specified by the function user
def sepalwidth_cut(x):
Sepalwidth = irisdata.loc[irisdata["Sepal.Width"] > x]
return Sepalwidth
print sepalwidth_cut(3)

#Write the data for a given species to a comma-demilited file with the given species name as the file name: Hint: look at + or % to concatenate your species name and ".csv"
def species_cut(x):
x = irisdata[irisdata["Species"]=="virginica"]
x.to_csv("virginica")
return x
print species_cut("virginica")
5 changes: 5 additions & 0 deletions head.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pandas as pd
iris = pd.read_csv("/Users/Rachel R/Desktop/data-shell/IBC_EX6/iris.csv")
n = 5
head = iris[0:n]
print(head)
51 changes: 51 additions & 0 deletions setosa.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
,Sepal.Length,Sepal.Width,Petal.Length,Petal.Width,Species
0,5.1,3.5,1.4,0.2,setosa
1,4.9,3.0,1.4,0.2,setosa
2,4.7,3.2,1.3,0.2,setosa
3,4.6,3.1,1.5,0.2,setosa
4,5.0,3.6,1.4,0.2,setosa
5,5.4,3.9,1.7,0.4,setosa
6,4.6,3.4,1.4,0.3,setosa
7,5.0,3.4,1.5,0.2,setosa
8,4.4,2.9,1.4,0.2,setosa
9,4.9,3.1,1.5,0.1,setosa
10,5.4,3.7,1.5,0.2,setosa
11,4.8,3.4,1.6,0.2,setosa
12,4.8,3.0,1.4,0.1,setosa
13,4.3,3.0,1.1,0.1,setosa
14,5.8,4.0,1.2,0.2,setosa
15,5.7,4.4,1.5,0.4,setosa
16,5.4,3.9,1.3,0.4,setosa
17,5.1,3.5,1.4,0.3,setosa
18,5.7,3.8,1.7,0.3,setosa
19,5.1,3.8,1.5,0.3,setosa
20,5.4,3.4,1.7,0.2,setosa
21,5.1,3.7,1.5,0.4,setosa
22,4.6,3.6,1.0,0.2,setosa
23,5.1,3.3,1.7,0.5,setosa
24,4.8,3.4,1.9,0.2,setosa
25,5.0,3.0,1.6,0.2,setosa
26,5.0,3.4,1.6,0.4,setosa
27,5.2,3.5,1.5,0.2,setosa
28,5.2,3.4,1.4,0.2,setosa
29,4.7,3.2,1.6,0.2,setosa
30,4.8,3.1,1.6,0.2,setosa
31,5.4,3.4,1.5,0.4,setosa
32,5.2,4.1,1.5,0.1,setosa
33,5.5,4.2,1.4,0.2,setosa
34,4.9,3.1,1.5,0.2,setosa
35,5.0,3.2,1.2,0.2,setosa
36,5.5,3.5,1.3,0.2,setosa
37,4.9,3.6,1.4,0.1,setosa
38,4.4,3.0,1.3,0.2,setosa
39,5.1,3.4,1.5,0.2,setosa
40,5.0,3.5,1.3,0.3,setosa
41,4.5,2.3,1.3,0.3,setosa
42,4.4,3.2,1.3,0.2,setosa
43,5.0,3.5,1.6,0.6,setosa
44,5.1,3.8,1.9,0.4,setosa
45,4.8,3.0,1.4,0.3,setosa
46,5.1,3.8,1.6,0.2,setosa
47,4.6,3.2,1.4,0.2,setosa
48,5.3,3.7,1.5,0.2,setosa
49,5.0,3.3,1.4,0.2,setosa