pyradigms package¶
Module contents¶
This is the main pyradigms module
- class pyradigms.Pyradigm(entries: DataFrame | None = None, x: List[str] = _Nothing.NOTHING, y: List[str] = _Nothing.NOTHING, z: List[str] = _Nothing.NOTHING, sort_orders: Dict = _Nothing.NOTHING, filters: Dict = _Nothing.NOTHING, ignore: List[str] = _Nothing.NOTHING, print_columns: List[str] = ['Form'], print_sep: str = ' ')¶
Bases:
object
Pyradigm instances hold the data from which paradigms are created, as well as parameters and methods used to generate them.
- category_joiner = ' / '¶
The string(s) used to concatenate labels of categories combined on an axis.
- compose_paradigm(csv_output=None, **kwargs)¶
The central function of pyradigms, creating paradigms. In addition to the list below, you can pass any argument described for the
Pyradigm
class.- Parameters:
csv_output (str) – CSV file to save paradigm to.
- Returns:
If one paradigm is generated, a pandas DataFrame. If multiple paradigms are generated, a dict of DataFrames.
- decompose_paradigm(paradigm, z_value=None, **kwargs)¶
Decompose a paradigm by specifying the parameters shown on the x and y axes.
- Parameters:
paradigm (DataFrame) – The paradigm as a pandas DataFrame. Note: the y axis labels of the must be the index, not the first column. To achieve that, use
pd.read_csv("file.csv", dtype=str, index_col=0)
ordf.set_index()
x (list) – The parameters shown on the x axis (columns)
y (list) – The parameters shown on the y axis (index)
separators (list) – Strings by which x and y labels (combined categories) will be split.
print_column (str) – Name of the column where paradigm cells will be stored.
z_value (str) – if a z parameter is specified for the paradigm to be decomposed, you can assign a value manually.
Returns: a pandas DataFrame object
- entries: DataFrame¶
The data in a wide format pandas DataFrame
- filters: Dict¶
Pass parameter names as keys, value lists to be filtered as values. Example:
{"Number": ["SG", "DU"]}
- classmethod from_csv(path, data_format='wide', **kwargs)¶
Create a new Pyradigm object from a CSV file.
- Parameters:
path (str) – path to the CSV file to be read
data_format (str) –
"wide"
(default): Parameters in columns, entries in rows."long"
: Columns: ID, Parameter, Value"paradigm"
: Decompose a paradigm by specifying at least x and y (kwargs are passed toPyradigm.decompose_paradigm()
)
- Returns:
a
Pyradigm
object
- classmethod from_dataframe(df: DataFrame, data_format='wide', **kwargs)¶
Create a new Pyradigm from a pandas dataframe.
- Parameters:
df (DataFrame) – a pandas dataframe containing the data in wide format
- Returns:
a
Pyradigm
object
- classmethod from_dict(records)¶
Create a new Pyradigm object from a list of dicts (records)
- Parameters:
records (list) – a list containing dicts representing the data in wide format
- Returns:
a
Pyradigm
object
- classmethod from_text(text, x_sep=',', y_sep='\n')¶
Create a new Pyradigm object from a string.
- Parameters:
text (str) – a string containing the data in wide format
x_sep (str) – how columns are separated
y_sep (str) – how rows are separated
- Returns:
a
Pyradigm
object
- ignore: List[str]¶
Parameters which will be ignored completely.
- output_folder = None¶
The folder into which generated paradigms will be written.
- print_columns: List[str]¶
The column in wide format which holds the values in the cells (usually forms, IDs, values…)
- print_sep: str¶
The string used to combine columns to be printed in the cells
- separators = ['.']¶
The first item is used to concatenate labels of values combined in a column or row label. Subsequent items are only used when decomposing paradigms.
- sort_orders: Dict¶
Pass parameter names as keys, ordered value lists as values. Example:
{"Number": ["SG", "DU", "PL"]}
- to_long()¶
Arrange the entries in long format. If there is no column
ID
, one will be created.Returns: a pandas DataFrame object
- to_markdown(data_format='paradigm', pyd_kwargs=None, **kwargs)¶
Print a markdown representation of the data. **kwargs are passed to pandas’ to_markdown and to tabulate, so you can use
tablefmt
.- Parameters:
data_format (str) –
"paradigm"
(default): The data rendered as a paradigm."wide"
: Parameters in columns, entries in rows."long"
: Columns: ID, Parameter, Value
pyd_kwargs (dict) – Any parameters to be passed to
Pyradigm.compose_paradigm()
ifdata_format=="paradigm"
- Returns:
A markdown string.
- update(**kwargs)¶
- with_multi_index = False¶
If False, the value labels for categories sharing an axis will be joined in single cells. If True, a pandas
MultiIndex
will be used.
- x: List[str]¶
The parameters to be represented on the x axis
- y: List[str]¶
The parameters to be represented on the y axis
- z: List[str]¶
The parameters to be represented on the z axis