From fa7ed6a1d42a53635299d6285b14e4f7f58df478 Mon Sep 17 00:00:00 2001 From: rachel Date: Thu, 11 Oct 2018 23:31:52 -0400 Subject: [PATCH 1/4] head.py --- head.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 head.py diff --git a/head.py b/head.py new file mode 100644 index 0000000..bdeca86 --- /dev/null +++ b/head.py @@ -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) From f0ae31148a80e8621a9b2a03a9fbaf837ea96181 Mon Sep 17 00:00:00 2001 From: rachel Date: Fri, 12 Oct 2018 00:47:59 -0400 Subject: [PATCH 2/4] EX6_Answers.py --- EX6_Answers.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 EX6_Answers.py diff --git a/EX6_Answers.py b/EX6_Answers.py new file mode 100644 index 0000000..444756c --- /dev/null +++ b/EX6_Answers.py @@ -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) From 01bd24ca22fdc9aaa52bfa04980f64357feedba8 Mon Sep 17 00:00:00 2001 From: rachel Date: Fri, 12 Oct 2018 00:48:19 -0400 Subject: [PATCH 3/4] setosa.csv --- setosa.csv | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 setosa.csv diff --git a/setosa.csv b/setosa.csv new file mode 100644 index 0000000..16bacc1 --- /dev/null +++ b/setosa.csv @@ -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 From 384abf3b4888556001d48df5523a7df988a97ca2 Mon Sep 17 00:00:00 2001 From: rachel Date: Tue, 16 Oct 2018 14:06:16 -0400 Subject: [PATCH 4/4] EX7_answers.py --- EX7_answers.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 EX7_answers.py diff --git a/EX7_answers.py b/EX7_answers.py new file mode 100644 index 0000000..c94966e --- /dev/null +++ b/EX7_answers.py @@ -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")