excel¶
excel ¶
Excel ¶
Thin wrapper around a pandas dataframe loaded from (or destined for) an .xlsx file, used throughout build for both input dictionaries and the output spreadsheet.
Source code in source/src/imarina_load_researchers/core/excel.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
__init__ ¶
Loads an Excel file into a dataframe, or starts with an empty one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | Path | None | Path to the | required |
skiprows | int | Number of leading rows to skip before the header, forwarded to | 0 |
header | int | None | Row index to use as the column header, forwarded to | 0 |
Source code in source/src/imarina_load_researchers/core/excel.py
parse_two_columns ¶
parse_two_columns(key: int, value: int, func_apply_key: Callable[[Any], Any] | None = None, func_apply_value: Callable[[Any], Any] | None = None) -> dict[Any, Any]
Builds a {key: value} dict out of two columns of this sheet.
Used to load the two-column translation-dictionary spreadsheets (e.g. country name mappings) into lookup dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | int | Column index to use as dict keys. | required |
value | int | Column index to use as dict values. | required |
func_apply_key | Callable[[Any], Any] | None | Optional function applied to every key value before building the dict. | None |
func_apply_value | Callable[[Any], Any] | None | Optional function applied to every value before building the dict. | None |
Returns:
| Type | Description |
|---|---|
dict[Any, Any] | dict[Any, Any]: The resulting key/value mapping. |
Source code in source/src/imarina_load_researchers/core/excel.py
empty ¶
Drops all rows from the dataframe, keeping its columns/dtypes/header.
to_excel ¶
Writes this dataframe out to an .xlsx file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path | Path | Destination path for the spreadsheet. | required |
Source code in source/src/imarina_load_researchers/core/excel.py
__copy__ ¶
Returns a shallow copy of this Excel with an independently-copied dataframe.
Returns:
| Name | Type | Description |
|---|---|---|
Excel | Excel | A new |
Source code in source/src/imarina_load_researchers/core/excel.py
get_val ¶
Reads a cell value from a dataframe row, normalizing pandas' NaN to None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row | Series | The row to read from. | required |
field | str | The column/field name to read. | required |
Returns:
| Name | Type | Description |
|---|---|---|
Any | Any | The cell value, or |
Source code in source/src/imarina_load_researchers/core/excel.py
get_str_val ¶
Reads a cell value from a dataframe row as a stripped string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row | Series | The row to read from. | required |
field | str | The column/field name to read. | required |
Returns:
| Name | Type | Description |
|---|---|---|
str | str | The cell value converted to |