-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemgUtils.py
More file actions
28 lines (24 loc) · 882 Bytes
/
emgUtils.py
File metadata and controls
28 lines (24 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
import pandas as pd
import numpy as np
def load_csv(file_path):
try:
df = pd.read_csv(file_path, header=1)
print("CSV data successfully loaded")
print(df.head()) # Print the first few rows
return df
except FileNotFoundError:
print(f"Error: File not found at '{file_path}'")
except pd.errors.EmptyDataError:
print("Error: File is empty")
except pd.errors.ParserError:
print("Error: Failed to parse CSV file")
def preproc(df, rmsWind):
abs_df = df.abs()
rms_df = abs_df.rolling(window=int(rmsWind)).apply(lambda x: np.sqrt(np.mean(x**2)), raw=True)
return rms_df
def save_csv(df, save_path):
try:
df.to_csv(save_path, index=False)
print(f"Data successfully saved to '{save_path}'")
except Exception as e:
print(f"Error: Could not save file to '{save_path}'. {e}")