-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (43 loc) · 1.64 KB
/
main.py
File metadata and controls
51 lines (43 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
data = pd.read_csv('data.csv')
print(data.columns) # Should output Name, Age, Marks
class DataAnalyzer:
def __init__(self, csv_path):
self.df = pd.read_csv(csv_path)
def calculate_average(self, column):
avg = self.df[column].mean()
print(f'Average for {column}: {avg:.2f}')
return avg
def plot_bar_chart(self, x_col, y_col):
plt.figure(figsize=(8,5))
plt.bar(self.df[x_col], self.df[y_col], color='skyblue')
plt.xlabel(x_col)
plt.ylabel(y_col)
plt.title(f'Bar Chart of {y_col} vs {x_col}')
plt.show()
def plot_scatter(self, x_col, y_col):
plt.figure(figsize=(8,5))
plt.scatter(self.df[x_col], self.df[y_col], c='tomato', alpha=0.7)
plt.xlabel(x_col)
plt.ylabel(y_col)
plt.title(f'Scatter Plot of {y_col} vs {x_col}')
plt.show()
def plot_heatmap(self):
corr = data[['Age', 'Marks']].corr() # Only numeric columns!
sns.heatmap(corr, annot=True)
plt.title('Correlation Heatmap')
plt.show()
# corr = self.df.corr()
# plt.figure(figsize=(10,8))
# sns.heatmap(corr, annot=True, cmap='viridis')
# plt.title('Correlation Heatmap')
# plt.show()
# Usage example
if __name__ == '__main__':
analyzer = DataAnalyzer('data.csv')
analyzer.calculate_average('Marks') # Replace with actual column name
analyzer.plot_bar_chart('Name', 'Marks') # Replace with actual columns
analyzer.plot_scatter('Age', 'Marks') # Replace with actual columns
analyzer.plot_heatmap()