Issue
I am trying to put many AcqKnowledge data files from a folder into different data frames based on the channel data so that I may do additional operations etc with them. When I try to use the following syntax, I cannot get the data files to join with one another. Any suggestions would be appreciated!
I am able to read one file at a time with a similar approach.
this is a resource on bioread: https://github.com/uwmadison-chm/bioread
import pandas as pd
from bioread import read_file
# Specify the folder containing your Acq files
folder_path = r"C:\path\to\your\acq_files"
# Initialize empty lists for EDA and ECG data
eda_data = []
ecg_data = []
# Iterate through Acq files in the folder
for file_name in os.listdir(folder_path):
if file_name.endswith(".acq"):
file_path = os.path.join(folder_path, file_name)
# Read the Acq file
acq_data = read_file(file_path)
# Extract data for EDA channel
eda_channel_name = 'GSR - EDA100C'
if eda_channel_name in acq_data.channels:
eda_data.extend(acq_data[eda_channel_name].data.tolist())
# Extract data for ECG channel
ecg_channel_name = 'ECG - ECG100C'
if ecg_channel_name in acq_data.channels:
ecg_data.extend(acq_data[ecg_channel_name].data.tolist())
# Create DataFrames for EDA and ECG
df_eda = pd.DataFrame({"GSR - EDA100C": eda_data})
df_ecg = pd.DataFrame({"ECG - ECG100C": ecg_data})
# Print the first 10 rows of the EDA DataFrame
print("First 10 rows of the EDA DataFrame:")
print(df_eda.head(10))
# Print the first 10 rows of the ECG DataFrame
print("\nFirst 10 rows of the ECG DataFrame:")
print(df_ecg.head(10))
First 10 rows of the combined DataFrame: Empty DataFrame Columns: [] Index: []
Could you help me resolve this?
Solution
I think the main problem here is that you're doing membership test operations using an str
against a list of Channel
objects. This is why the checks, you do, never evalute to True
, the lists remain empty and hence the DataFrames too. So, here is a proposition to fix your code :
Move lines 20 and 25 outside the loop (put them before) and update the inner if
blocks to this :
channels = acq_data.channels
for idx, ch in enumerate(map(str, channels)):
if eda_channel_name in ch:
eda_data.extend(channels[idx].data)
elif ecg_channel_name in ch:
ecg_data.extend(channels[idx].data)
Answered By - Timeless
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.