Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Answers #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions answers7REAL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#1
>>> import pandas as cd
>>> irisdata=cd.read_csv('iris.csv')
>>> def custom_function():
... iris_1=irisdata.iloc[1:150,:]
... iris_2=iris_1.iloc[::2]
... return iris_2
>>> print(custom_function())

#2

#return the number of observations for a given species included in the data set
>>> def custom_function():
... data=pd.read_csv("iris.csv")
... return (data['Species'].value_counts())

#return a dataframe for flowers with Sepal.Width greater than a value specified by the function user
>>> def custom_function(x):
... return data.loc[data['Sepal.Width']>x]

#write the data for a given species to a comma-delimited file with the given species name as the file name
import pandas
data=pandas.read_csv("iris.csv")
def custom_function(x):
y=data.loc[data['Species']==x]
y.to_csv('%s.csv' % x)
print(custom_function('setosa'))