diff --git a/setosa.csv b/setosa.csv new file mode 100644 index 0000000..00246f0 --- /dev/null +++ b/setosa.csv @@ -0,0 +1,51 @@ +Sepal.Length,Sepal.Width,Petal.Length,Petal.Width,Species +5.1,3.5,1.4,0.2,setosa +4.9,3.0,1.4,0.2,setosa +4.7,3.2,1.3,0.2,setosa +4.6,3.1,1.5,0.2,setosa +5.0,3.6,1.4,0.2,setosa +5.4,3.9,1.7,0.4,setosa +4.6,3.4,1.4,0.3,setosa +5.0,3.4,1.5,0.2,setosa +4.4,2.9,1.4,0.2,setosa +4.9,3.1,1.5,0.1,setosa +5.4,3.7,1.5,0.2,setosa +4.8,3.4,1.6,0.2,setosa +4.8,3.0,1.4,0.1,setosa +4.3,3.0,1.1,0.1,setosa +5.8,4.0,1.2,0.2,setosa +5.7,4.4,1.5,0.4,setosa +5.4,3.9,1.3,0.4,setosa +5.1,3.5,1.4,0.3,setosa +5.7,3.8,1.7,0.3,setosa +5.1,3.8,1.5,0.3,setosa +5.4,3.4,1.7,0.2,setosa +5.1,3.7,1.5,0.4,setosa +4.6,3.6,1.0,0.2,setosa +5.1,3.3,1.7,0.5,setosa +4.8,3.4,1.9,0.2,setosa +5.0,3.0,1.6,0.2,setosa +5.0,3.4,1.6,0.4,setosa +5.2,3.5,1.5,0.2,setosa +5.2,3.4,1.4,0.2,setosa +4.7,3.2,1.6,0.2,setosa +4.8,3.1,1.6,0.2,setosa +5.4,3.4,1.5,0.4,setosa +5.2,4.1,1.5,0.1,setosa +5.5,4.2,1.4,0.2,setosa +4.9,3.1,1.5,0.2,setosa +5.0,3.2,1.2,0.2,setosa +5.5,3.5,1.3,0.2,setosa +4.9,3.6,1.4,0.1,setosa +4.4,3.0,1.3,0.2,setosa +5.1,3.4,1.5,0.2,setosa +5.0,3.5,1.3,0.3,setosa +4.5,2.3,1.3,0.3,setosa +4.4,3.2,1.3,0.2,setosa +5.0,3.5,1.6,0.6,setosa +5.1,3.8,1.9,0.4,setosa +4.8,3.0,1.4,0.3,setosa +5.1,3.8,1.6,0.2,setosa +4.6,3.2,1.4,0.2,setosa +5.3,3.7,1.5,0.2,setosa +5.0,3.3,1.4,0.2,setosa diff --git a/solution_1.py b/solution_1.py new file mode 100644 index 0000000..9788e2a --- /dev/null +++ b/solution_1.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +""" +Created on Thu Oct 11 10:05:39 2018 + +@author: mlpoterek +""" + +def head (str, n) : + with open (str) as my_file: + first_lines = [next(my_file) for x in xrange(n)] + print(first_lines) + +head("iris.csv", 2) #to call function with n=2 diff --git a/solution_2.py b/solution_2.py new file mode 100644 index 0000000..0f5e44c --- /dev/null +++ b/solution_2.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +""" +Created on Thu Oct 11 13:09:43 2018 + +@author: mlpoterek +""" + +from pandas import DataFrame, read_csv +import pandas as pd + +location = r'/Users/mlpoterek/Biocomp/IBC_EX6/iris.csv' +df = pd.read_csv(location) + +#Print the last 2 rows in the last 2 columns +last_rows = df.tail(2) +last_cols = last_rows[['Petal.Width', 'Species']] +print(last_cols) + +#Number of observations of each species +spec_count = df['Species'].value_counts() +print(spec_count) + +#Rows with Sepal.Width > 3.5 +sepal_rows = df[df['Sepal.Width'] > 3.5] +print(sepal_rows) + +#Write the data for the species setosa to a csv file 'setosa.csv' +setosa_rows = df[df['Species']=='setosa'] +setosa_rows.to_csv("setosa.csv",sep = ',', index = False) + +#Mean, min, and max of 'Petal.Length' for observations from virginica +virginica_rows = df[df['Species']=='virginica'] +v_mean = virginica_rows['Petal.Length'].mean() +v_min = virginica_rows['Petal.Length'].min() +v_max = virginica_rows['Petal.Length'].max() +print(v_mean, v_min, v_max) \ No newline at end of file