-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
29 lines (26 loc) · 882 Bytes
/
utils.py
File metadata and controls
29 lines (26 loc) · 882 Bytes
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
import pandas as pd
def import_data(file_directory):
if file_directory.endswith('.csv'):
data = pd.read_csv(file_directory)
elif file_directory.endswith('.xlsx'):
data = pd.read_excel(file_directory)
else:
raise ValueError("Unsupported file format. Please use .csv or .xlsx files.")
return data
def export_data(data, file_directory, file_type='csv'):
if file_type == 'xlsx':
data.to_excel(file_directory, index=False)
else:
data.to_csv(file_directory, index=False)
def get_statistics(data):
stats = {
'Count': data.count(),
'Mean': data.mean(),
'Median': data.median(),
'Mode': data.mode().iloc[0] if not data.mode().empty else 'N/A',
'Std': data.std(),
'Min': data.min(),
'Max': data.max(),
'Range': data.max() - data.min()
}
return stats