-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathread_mock_data.py
55 lines (44 loc) · 1.58 KB
/
read_mock_data.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
47
48
49
50
51
52
53
54
55
import pandas as pd
import matplotlib.pyplot as plt
import chardet
# First detect the encoding
with open('MOCK_DATA.csv', 'rb') as file:
raw_data = file.read()
result = chardet.detect(raw_data)
encoding = result['encoding']
print(f"File encoding: {encoding}")
"""_summary_
This code does the following:
1. adfadf
2. asdfasdf
3. sdfasdfadsf
"""
# Read the CSV file with the detected encoding
df = pd.read_csv('MOCK_DATA.csv', encoding=encoding)
# Remove rows where last_name is empty or null
df = df.dropna(subset=['last_name'])
df = df[df['last_name'].str.strip() != '']
# Remove rows where height is missing, empty, or null
df = df.dropna(subset=['height'])
print(f"Number of rows after removing empty last names and invalid heights: {len(df)}")
# Display the first few rows of the DataFrame
print("\nFirst 5 rows of the data:")
print(df.head())
# Display basic information about the DataFrame
print("\nDataFrame info:")
print(df.info())
# Display basic statistical summary
print("\nBasic statistical summary:")
print(df.describe())
# Create a histogram for height distribution
plt.figure(figsize=(10, 6))
plt.hist(df['height'], bins=30, edgecolor='black')
plt.title('Distribution of Heights')
plt.xlabel('Height')
plt.ylabel('Frequency')
plt.grid(True, alpha=0.3)
# Add mean and median lines
plt.axvline(df['height'].mean(), color='red', linestyle='dashed', linewidth=1, label=f'Mean: {df["height"].mean():.2f}')
plt.axvline(df['height'].median(), color='green', linestyle='dashed', linewidth=1, label=f'Median: {df["height"].median():.2f}')
plt.legend()
plt.show()