-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataFrame_Checker.py
More file actions
49 lines (39 loc) · 1.7 KB
/
Copy pathDataFrame_Checker.py
File metadata and controls
49 lines (39 loc) · 1.7 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
import pandas as pd
class DataFrameChecker:
def __init__(self, data):
self.data = data
def check_errors(self):
has_errors = False
print("Errors in DataFrame:")
for column in self.data.columns:
try:
# Check for missing values in the column
if self.data[column].isnull().any():
has_errors = True
print("Error: Missing values found in column:", column)
print(self.data[self.data[column].isnull()])
# Check for out-of-range errors
errors = self.data[(self.data[column] < self.data[column].min()) | (self.data[column] > self.data[column].max())]
if not errors.empty:
has_errors = True
print("Errors found in column:", column)
print(errors)
except TypeError:
print("Error: Non-numeric values found in column:", column)
has_errors = True
if not has_errors:
print("No errors found in DataFrame")
def check_duplicates(self):
duplicates = self.data[self.data.duplicated()]
if not duplicates.empty:
print("Duplicates found in DataFrame:")
print(duplicates)
else:
print("No duplicates found in DataFrame")
def check_missing_values(self):
missing_values = self.data.isnull().sum()
if missing_values.sum() > 0:
print("Missing values found in DataFrame:")
print(missing_values[missing_values > 0])
else:
print("No missing values found in DataFrame")