Lesson 16 exercies Flashcards
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.
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)}”)
Print the keys, number of rows-columns, feature names and the description of the Iris data.
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())
Create a Bar plot to get the frequency of the three species of the Iris data.
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()
Create a graph to find relationship between the sepal length and width.
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()