diff --git a/#1.py b/#1.py new file mode 100644 index 0000000..0a52faa --- /dev/null +++ b/#1.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Oct 25 13:48:30 2018 + +@author: vysan +""" + +import pandas as pd +def oddrows(filename): + data=pd.read_csv(filename,header=0,sep=",") + return data.iloc[1::2] +print oddrows("filename") #filename is the name of the file with your dataframe + + + + + diff --git a/#2.py b/#2.py new file mode 100644 index 0000000..130ac22 --- /dev/null +++ b/#2.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Oct 25 14:15:49 2018 + +@author: vysan +""" +#return number of observations for given species +import pandas as pd +data=pd.read_csv("iris.csv",header=0,sep=",") +def count(name): + return (data["Species"]==name).sum() +count("name") #name is the name of the species of interest + + + +#return dataframe for flowers with Sepal.Width > than specified value +import pandas as pd +data=pd.read_csv("iris.csv",header=0,sep=",") +def sepalwidthgreaterthan(x): + return data[data["Sepal.Width"] > x] +sepalwidthgreaterthan(x) #x is the specified value by the user + + + +#write data for given species to comma-delimited file +#with name "speciesname".csv +import pandas as pd +data=pd.read_csv("iris.csv",header=0,sep=",") +def newfilefor(name): + new=data[data["Species"]==name] + new.to_csv(str(name)+".csv",sep=(",")) +newfilefor("name") #name is the name of the given species + + +