cpm.utils
cpm.utils.pandas_to_dict(df=None, participant='ppt', stimuli='stimulus', feedback='feedback', **kwargs)
Convert a pandas dataframe to a dictionary suitable for use with the CPM wrappers.
The pandas dataframe should have a column for each stimulus, and a column for each feedback, and a column for a participant identifier. Each row should be a single trial, and each participant should have a unique number in the participant column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
pandas dataframe
|
The dataframe to convert |
None
|
stimuli |
str, optional
|
The prefix for each stimulus column in the pandas DataFrame, by default "stimulus". |
'stimulus'
|
participant |
str, optional
|
The column name for the participant number, by default "ppt". |
'ppt'
|
**kwargs |
dict, optional
|
Any other keyword arguments to pass to the pandas DataFrame. |
{}
|
Returns:
Type | Description |
---|---|
list
|
A list of dictionaries, each dictionary containing the stimuli and feedback for a single participant. |
cpm.utils.dict_to_pandas(dict)
Convert a dictionary to a pandas dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dict |
dict
|
The dictionary to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
pandas |
dataframe
|
The pandas dataframe converted from dict. |
cpm.utils.load(file)
Load a file from disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
str
|
The file to load. |
required |
Returns:
Type | Description |
---|---|
object
|
The object loaded from the file. |