-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathdata_analyis.py
46 lines (40 loc) · 1.32 KB
/
data_analyis.py
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
import pandas as pd
import matplotlib.pyplot as plt
def load_data(file_path):
"""Load data from a CSV file."""
try:
data = pd.read_excel(file_path)
return data
except FileNotFoundError:
print("File not found. Please provide a valid file path.")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
def analyze_data(data):
"""Perform basic data analysis."""
if data is not None:
# Display summary statistics
print("Summary Statistics:")
print(data.describe())
# Plot histograms for numeric columns
print("Histograms:")
for col in data.select_dtypes(include=['int', 'float']):
data[col].plot(kind='hist', bins=10)
plt.title(col)
plt.xlabel(col)
plt.ylabel('Frequency')
plt.show()
# Plot bar plot for the class label (string type)
class_label_counts = data['Class'].value_counts()
class_label_counts.plot(kind='bar')
plt.title('Class Label Distribution')
plt.xlabel('Class Label')
plt.ylabel('Count')
plt.show()
def main():
file_path = input("Enter the path to the CSV file: ")
data = load_data(file_path)
analyze_data(data)
if __name__ == "__main__":
main()