Lesson 16 exercies Flashcards

1
Q

Load the iris data from a csv file into a dataframe and print the shape of the data, type of the data and first 3 rows.

A

df = pd.read_csv(r”C:\Users\User\Documents\CFG_DATA\data\iris.csv”)
print(f”The shape of the data is {df.shape}”)
print(f” The data type is: {df.dtypes}”)
print(f”The first three rows are: {df.head(3)}”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Print the keys, number of rows-columns, feature names and the description of the Iris data.

A

print(f”Keys: {df.keys()}”)

rows = df.shape[0]
columns = df.shape[1]
print(f”the rows are {rows}, and the columns are {columns}”)
print(df.describe())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create a Bar plot to get the frequency of the three species of the Iris data.

A

frequency = iris_data.groupby(‘species’)[‘species’].count()

plt.bar(frequency.index, frequency.values, color=’plum’, width=.4)
plt.xlabel(“Species of Iris”)
plt.ylabel(“Frequency”)
plt.title(“Frequency of Species of Iris”)
plt.xticks(rotation=25)
plt.show()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Create a graph to find relationship between the sepal length and width.

A

sepal_length = df[‘sepal_length’].to_list()
sepal_width = df[‘sepal_width’].to_list()

plt.scatter(sepal_length, sepal_width)
plt.xlabel(‘sepal length’)
plt.ylabel(‘sepal width’)
plt.title(‘title’)
plt.show()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly