Skip to content

Commit

Permalink
add move_sheet method
Browse files Browse the repository at this point in the history
  • Loading branch information
itlubber committed Nov 16, 2023
1 parent 598fa55 commit 011ad4d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
7 changes: 4 additions & 3 deletions docs/source/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ init_setting(seed=10)

[`germancredit`](https://archive.ics.uci.edu/dataset/144/statlog+german+credit+data) 数据集中包含类别型变量、数值型变量、好坏标签,共1000条数据,由于数据集中不包含缺失值,为了模拟实际生产中的真实数据,笔者将在固定随机种子的情况下随机替换数据集中的部分内容为 `np.nan`

<!-- <details>
<summary>数据字典</summary> -->
<details>

<summary>数据字典</summary>

**序号** | **类型** | **特征名** | **释义**
:------:|:------:|:--------------------------------------------------------:|:---------------:
Expand All @@ -119,7 +120,7 @@ init_setting(seed=10)
19 | 类别型 | telephone | 电话
20 | 类别型 | foreign worker | 外籍工人

<!-- </details> -->
</details>

<br>

Expand Down
20 changes: 16 additions & 4 deletions scorecardpipeline/excel_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
class ExcelWriter:

def __init__(self, style_excel=None, style_sheet_name="初始化", mode="replace", fontsize=10, font='楷体', theme_color='2639E9', opacity=0.85):
"""
excel 文件内容写入公共方法
"""excel 写入方法
:param style_excel: 样式模版文件,默认当前路径下的 template.xlsx ,如果项目路径调整需要进行相应的调整
:param style_excel: 样式模版文件,默认安装包路径下的 template.xlsx ,如果路径调整需要进行相应的调整
:param style_sheet_name: 模版文件内初始样式sheet名称,默认即可
:param mode: 写入模式,默认 replace,可选 replace、append,当选择 append 模式时会将已存在的excel中的内容复制到新的文件中
:param fontsize: 插入excel文件中内容的字体大小,默认 10
:param font: 插入excel文件中内容的字体,默认 楷体
:param theme_color: 主题色,默认 2639E9,注意不包含 #
Expand Down Expand Up @@ -105,6 +105,18 @@ def get_sheet_by_name(self, name):

return worksheet

def move_sheet(self, worksheet, offset: int = 0, index: int = None):
"""移动 sheet 位置
:param worksheet: 需要移动的sheet,支持输入字符串和Worksheet
:param offset: 需要移动的相对位置,默认 0,在传入 index 时参数不生效
:param index: 需要移动到的位置索引,超出移动到最后
"""
if index:
offset = -len(self.workbook.sheetnames) + 1 + index

self.workbook.move_sheet(worksheet, offset=offset)

def insert_value2sheet(self, worksheet, insert_space, value="", style="content", auto_width=False):
"""
向sheet中的某个单元格插入某种样式的内容
Expand Down Expand Up @@ -504,7 +516,7 @@ def save(self, filename, close=True):
if i == _workbook[_sheet_name].max_row - 1:
_worksheet.column_dimensions[get_column_letter(j + 1)].width = _workbook[_sheet_name].column_dimensions[get_column_letter(j + 1)].width

self.workbook.move_sheet(_worksheet, offset=-len(self.workbook.sheetnames) + 1)
# self.workbook.move_sheet(_worksheet, offset=-len(self.workbook.sheetnames) + 1)

_workbook.close()

Expand Down
1 change: 0 additions & 1 deletion scorecardpipeline/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ def feature_bin_stats(cls, data, feature, target="target", rules=None, method='s
, empty_separate=empty_separate
, min_n_bins=2
, max_n_bins=max_n_bins
, max_n_prebins=20
, min_bin_size=min_bin_size
, max_bin_size=max_bin_size
, **kwargs
Expand Down

0 comments on commit 011ad4d

Please sign in to comment.