Data Visualization
Data Visualization
Triangle patterns:
Def fibonacci(n):
A, b = 0, 1
A, b = b, a + b
Return a
Def numeric_triangle(rows):
Numeric_triangle(rows)
Output:
12
123
1234
12345
Iris = load_iris()
Df = pd.DataFrame(iris.data, columns=iris.feature_names)
Print(“\nBasic Statistics:\n”,
Output:
Sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
Sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
5.0 10
5.1 9
6.3 7
Question 3 : On the Iris Data Set Show the addition of new columns, perform
filtering based on acolumn value and show the use of group by function.
Import pandas as pd
Iris = load_iris()
Df = pd.DataFrame(iris.data, columns=iris.feature_names)
Output :
Sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
petal area
Sepal length (cm) petal length (cm) petal width (cm) petal area
Import pandas as pd
Iris = load_iris()
Df = pd.DataFrame(iris.data, columns=iris.feature_names)
Sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
petal area
Sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
petal area
Sepal length (cm) petal length (cm) petal width (cm) petal area
Question 5: On the height - weight DataSet print the top 5, bottom 5, and
random rows. Group bythe height column and update the height of students
in the group having no. ofstudents greater than 70.
Import pandas as pd
Height_groups = df.groupby(“Height”).size().reset_index(name=”Student
Count”)
Output:
Height Weight
0 150.0 50.0
1 160.2 65.5
2 155.5 58.3
3 170.0 75.0
4 165.1 68.4
Bottom 5 Rows
Height Weight
95 165.0 68.0
96 155.8 59.0
97 172.5 78.3
98 167.0 70.2
99 160.0 65.0
Random Sample Rows
Height Weight
42 172.0 77.5
67 158.5 60.8
23 161.0 64.2
89 153.0 55.1
12 170.0 74.0
0 150.0 10
1 155.5 25
2 160.0 80
3 165.0 95
4 170.0 60
Height Weight
0 150.0 50.0
2 155.5 58.3
3 170.0 75.0
Question 6: Show the use of shape, size, type, dtypes, columns and info
properties of a DataFrame.
import pandas as pd
data = {
"Name": ["Alice", "Bob", "Charlie", "David", "Eva"],
df = pd.DataFrame(data)
print("\nDataFrame Info:")
df.info()
Output:
Size of DataFrame: 20
Name object
Age int64
Salary int64
Department object
Dtype: object
Columns in DataFrame
Summary Info
DataFrame Info:
<class ‘pandas.core.frame.DataFrame’>
RangeIndex: 5 entries, 0 to 4
Question 7: Draw a line chart exploring its styling properties like figsize,
xlabel, ylabel, title,subtitle, color, marker, linestyle, linewidth.
Years = [2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024]
Sales = [10, 15, 12, 20, 18, 25, 30, 35, 40, 38] # Sales in millions
Plt.plot(years, sales,
Plt.show()
Output :--‐-------
Question 8: Draw a scatter plot exploring its properties like color, alpha, size,
labels.
Budget = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
Sales = [15, 25, 35, 30, 55, 60, 70, 85, 90, 100]
Plt.scatter(budget, sales,
Plt.show()
Output: ------
Products = [“Product A”, “Product B”, “Product C”, “Product D”, “Product E”]
Axs[0].bar(products, sales,
Axs[1].barh(products, sales,
Plt.tight_layout()
Plt.show()
Output : ------
Import numpy as np
Plt.hist(data,
# Add legend
Plt.legend(fontsize=12)
Plt.show()
Output :-------
QQuestion11: Draw a pie chart exploring its properties like labels, colors,
radius, explode, shadow,autopct.
Plt.pie(sizes,
# Add Title
Plt.show()
Output:
Question 12 : Draw line chart, Scatter plot, histogram on the iris data set
with styling.
Import pandas as pd
Iris = load_iris()
Df = pd.DataFrame(iris.data, columns=iris.feature_names)
Axes[0].legend(fontsize=12)
Axes[0].grid(True)
Axes[1].grid(True)
### 3️⃣HISTOGRAM – Petal Length Distribution ###
Axes[2].legend(fontsize=12)
Axes[2].grid(True)
Plt.tight_layout()
Plt.show()
Output :
Import pandas as pd
Iris = load_iris()
Df = pd.DataFrame(iris.data, columns=iris.feature_names)
Plt.figure(figsize=(10, 6))
Box = sns.boxplot(data=df,
Plt.grid(True)
Plt.show()