-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_analysis.py
More file actions
48 lines (40 loc) · 1.1 KB
/
Copy pathcsv_analysis.py
File metadata and controls
48 lines (40 loc) · 1.1 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
import pandas as pd
import matplotlib.pyplot as plt
# Load the CSV file
data = pd.read_csv("titanic.csv")
# Display first 5 rows
print("First 5 Rows:")
print(data.head())
# Display column names
print("\nColumns:")
print(data.columns)
# Display dataset information
print("\nDataset Information:")
print(data.info())
# Display statistical summary
print("\nStatistical Summary:")
print(data.describe())
# Calculate average age
print("\nAverage Age:")
print(data["age"].mean())
# Bar Chart
data["class"].value_counts().plot(kind="bar")
plt.title("Passengers by Class")
plt.xlabel("Class")
plt.ylabel("Number of Passengers")
plt.show()
# Scatter Plot
plt.scatter(data["age"], data["fare"])
plt.title("Age vs Fare")
plt.xlabel("Age")
plt.ylabel("Fare")
plt.show()
# Heatmap
plt.imshow(data.corr(numeric_only=True), cmap="coolwarm")
plt.colorbar()
plt.xticks(range(len(data.corr(numeric_only=True).columns)),
data.corr(numeric_only=True).columns, rotation=45)
plt.yticks(range(len(data.corr(numeric_only=True).columns)),
data.corr(numeric_only=True).columns)
plt.title("Correlation Heatmap")
plt.show()