From 9a2ba6af0b9243dd1991491e3634244d4c3f236a Mon Sep 17 00:00:00 2001 From: carson_git <543983849@qq.com> Date: Wed, 13 Jan 2021 11:40:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=97=E6=9F=A5=E6=89=BE=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/cusFuns/columnStrReplace/index.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 py/pdcopyist/src/cusFuns/columnStrReplace/index.py diff --git a/py/pdcopyist/src/cusFuns/columnStrReplace/index.py b/py/pdcopyist/src/cusFuns/columnStrReplace/index.py new file mode 100644 index 0000000..56691cb --- /dev/null +++ b/py/pdcopyist/src/cusFuns/columnStrReplace/index.py @@ -0,0 +1,23 @@ +from pdcopyist.src.cusFuns.core.DecoratorFuns import dt_handle_func, dt_args, dt_source_code +from pdcopyist.src.core import UIArgs as ty +import pandas as pd + + +m_col_with_type_select = ty.ColumnWithTypeSelect('目标列:') + + +def generate_code(*args, **kwargs): + col_name = f"'{m_col_with_type_select.get_value(kwargs['col_name'])}'" + to_replace = kwargs['to_replace'] + value = kwargs['value'] + return f'''df[{col_name}] = df[{col_name}].str.replace('{to_replace}','{value}')''' + + +@dt_source_code(generate_code) +@dt_handle_func('列内容替换') +@dt_args(col_name=m_col_with_type_select, + to_replace=ty.Input('查找内容:', placeholder='输入你需要查找的目标内容'), + value=ty.Input('替换成:', placeholder='输入替换的内容')) +def str_replace(df: pd.DataFrame, col_name: str, to_replace, value): + df[col_name] = df[col_name].str.replace(to_replace, value) + return df -- Gitee From eba42271802ffdfef95679f206642cce7f528767 Mon Sep 17 00:00:00 2001 From: carson_git <543983849@qq.com> Date: Wed, 13 Jan 2021 11:41:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?bug=20fix=EF=BC=9A=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=B1=A0=E4=B8=AD=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=8A=8A=E6=BA=90?= =?UTF-8?q?df=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=91=BD=E4=BB=A4=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=90=8E=EF=BC=8C=E6=95=B0=E6=8D=AE=E4=B9=9F=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=81=A2=E5=A4=8D=E4=BF=AE=E6=94=B9=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/pdcopyist/src/core/Proxy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/pdcopyist/src/core/Proxy.py b/py/pdcopyist/src/core/Proxy.py index 06adafd..33c1d89 100644 --- a/py/pdcopyist/src/core/Proxy.py +++ b/py/pdcopyist/src/core/Proxy.py @@ -176,7 +176,7 @@ df.columns=cols''') # df.columns=cols''') def get_df_data(self) -> pd.DataFrame: - self.df_proxy.set_obj_to_var('df', self.source_cache) + self.df_proxy.set_obj_to_var('df', self.source_cache.copy()) ret = self.df_proxy.run('df') self.df_proxy.cmdManager.clear_all_var() self.df_proxy.set_obj_to_var('pd', pd) -- Gitee