Data visualization manual Bhavya
1) Loading and Distinguishing Dependent and Independent Parameters
Code:-
import pandas as pd
# Corrected file path (with raw string or properly escaped backslashes)
data = pd.read_csv(r"C:\Users\ADMIN\Desktop\data sets\IRIS.csv")
# Selecting independent and dependent variables
X = data[['sepal_length', 'sepal_width']]
Y = data['species']
# Print the first few rows of the independent and dependent variables
print('Independent Variables:', X.head())
print('Dependent Variable:', Y.head())
out put
Independent Variables: sepal_length sepal_width
0 5.1 3.5
1 4.9 3.0
2 4.7 3.2
3 4.6 3.1
4 5.0 3.6
Dependent Variable: 0 Iris-setosa
1 Iris-setosa
2 Iris-setosa
3 Iris-setosa
4 Iris-setosa
Name: species, dtype: object
2) Exploring Data Visualization Tools
Code:-
import seaborn as sns
import matplotlib.pyplot as plt
# Load the 'tips' dataset
tips = sns.load_dataset('tips')
# Create a histogram of the 'total_bill' column
sns.histplot(tips['total_bill'], bins=20)
# Show the plot
plt.show()
out put
Data visualization manual Bhavya
3) Drawing Charts
Code:-
import matplotlib.pyplot as plt
categories = ['A', 'B', 'C']
values = [10, 20, 15]
plt.bar(categories, values, color=['red', 'blue', 'green'])
plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Bar Chart Example')
plt.show()
out put
Data visualization manual Bhavya
4) Drawing Graphs
Code:-
x = [1, 2, 3, 4, 5]
y = [10, 12, 15, 18, 25]
plt.plot(x, y, marker='o', linestyle='-', color='b')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Line Graph Example')
plt.grid()
plt.show()
out put
Data visualization manual Bhavya
5) Data Mapping
Code:-
import seaborn as sns
import numpy as np
matrix = np.random.rand(5, 5)
sns.heatmap(matrix, annot=True, cmap='coolwarm')
plt.show()
output:-
Data visualization manual Bhavya
6) Creating Scatter Plot Maps
Code:-
import seaborn as sns
import numpy as np
matrix = np.random.rand(5, 5)
tips = sns.load_dataset('tips')
sns.scatterplot(x='total_bill', y='tip', data=tips, hue='sex')
output:-
Data visualization manual Bhavya
7) Using BNF Notations
8) Working with REGEX
Code:
import re
email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
def validate_email(email):
return bool(re.match(email_pattern, email))
print(validate_email('test@example.com'))
print(validate_email('invalid-email'))
Data visualization manual Bhavya
out put
True
False
9) Visualizing Network Data
Code:-
import networkx as nx
G = nx.Graph()
G.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 1)])
nx.draw(G, with_labels=True, node_color='lightblue', edge_color='gray')
plt.show()
out put-
Data visualization manual Bhavya
10) Understanding Data Visualization Frameworks
Step 1: Understand various frameworks available for data visualization
- Matplotlib: Basic visualizations
- Seaborn: Statistical data visualization
- Plotly: Interactive charts
- NetworkX: Graph-based visualizations