<jupyter_start><jupyter_text>![image.png](attachment:a90f228a-f6c1-4632-8c2d-61337b9024f9.png)Pandas Practice====![IRIS, https://github.com/simonava5/fishers-iris-data](./images/iris.png)After the notebook with a lot of new input, let's start applying it totally by yourselves. For this purpose we will use one of the most standard real-life datasets: Its called Iris Dataset, and is all about the plant iris. Let's learn a little bit more about the dataset by looking at it.  Learning ObjectivesBy the end of this notebook, you will feel more comfortable with your newly acquired knowledge, as you will see that you can- load data from csv files into DataFrames- access data stored in DataFrames- use the general functions of a DataFrame to answer questions about the data- create insightful plots using the Pandas function `.plot()`- explain what conclusions you draw from these visualizations.<jupyter_code># import pandas
import pandas as pd
# load the data
df = pd.read_csv('data/iris.csv')<jupyter_output><empty_output><jupyter_text>Let us first have a look at the head of the table, maybe also on the last 10 rows...<jupyter_code>df.tail(10)<jupyter_output><empty_output><jupyter_text>How many irises are the data set?How many different species are there?<jupyter_code>df['species'].nunique()<jupyter_output><empty_output><jupyter_text>Calculate the mean, median, mode for petal length<jupyter_code>df['petal_length'].mean()
df['petal_length'].median()
df['petal_length'].mode()<jupyter_output><empty_output><jupyter_text>What can you conclude about the distribution for petal length?<jupyter_code>df['petal_length'].plot(kind='hist')<jupyter_output><empty_output><jupyter_text>What is the smallest and largest value for petal lenth?<jupyter_code>#iris[(iris['petal_length'].min()) & (iris['petal_length'].max())]
print("min: " + str(df['petal_length'].min()))
print("max: " + str(df['petal_length'].max()))<jupyter_output>min: 1.0
max: 6.9<jupyter_text>Calculate the variance and standard deviation for petal length<jupyter_code>df['petal_length'].std()
df['petal_length'].var()<jupyter_output><empty_output><jupyter_text>Calculate the basic descriptive statistics for all columns of the iris data set with a single command.<jupyter_code>df.describe()<jupyter_output><empty_output><jupyter_text>What is the overall average for sepal length?<jupyter_code>df['sepal_length'].mean()<jupyter_output><empty_output><jupyter_text>Use DataFrame grouping function to determine the count by species.<jupyter_code>a = df.groupby('species')
a.count()<jupyter_output><empty_output><jupyter_text>Use DataFrame grouping function to determine the average length and width of sepals and pedals by species.<jupyter_code>df.groupby('species').mean()<jupyter_output><empty_output><jupyter_text>Add the sum of the sepal width and length as a new column to your data frame.<jupyter_code>#a = iris['sepal_length'].sum()
#b = iris['sepal_width'].sum()
#c = a+b
#print(c)

df.eval('total_acidity = sepal_length + sepal_width', inplace = True)
df.columns<jupyter_output><empty_output><jupyter_text>Visualize petal length with a histogram<jupyter_code>df['petal_length'].plot(kind='hist')<jupyter_output><empty_output><jupyter_text>Describe the distribution<jupyter_code>df['petal_length'].describe()<jupyter_output><empty_output><jupyter_text>Which is more informative: the summary statistics or visualizations?<jupyter_code>#summary statistics<jupyter_output><empty_output><jupyter_text>Visualize petal length and width with a "scatter_matrix"<jupyter_code>df.plot(kind = "scatter", x= "petal_length", y = "petal_width")<jupyter_output><empty_output><jupyter_text>Describe the joint distribution<jupyter_code>The larger the Petal Length, the larger the Petal Width<jupyter_output><empty_output><jupyter_text>Create a new column with a rough estimate of petal area by multiplying petal length and width together.<jupyter_code>df.eval('petal_area = petal_length * petal_width', inplace = True)
df<jupyter_output><empty_output><jupyter_text>Create a new dataframe with petal areas greater than $1cm^2$.<jupyter_code>df.eval("petal_bigger = petal_area > 1", inplace = True)
df<jupyter_output><empty_output><jupyter_text>Create 3 new dataframes, one for each species. Use the entire dataset.<jupyter_code>a = df[(df['species'] == "Iris-setosa")]
#df.eval("i_s = df[(df['species'] == "Iris-setosa")]", inplace = True)
a
b = df[(df['species'] == "Iris-versicolor")]
b
c = df[(df['species'] == "Iris-virginica")]
c<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup