当前位置:   article > 正文

python 去除excel中重复行 # y.drop_duplicates(keep=‘first‘, inplace=True)_python keep=

python keep=

def removeDuplicateLineInfo():
    path = os.path.join(OutputPath, 'MacroInfo_cared_PLL0.xlsx')
    macro_info = pd.read_excel(path, sheet_name="frequency_plan", dtype=str, keep_default_na=False, header=0)

    # need to update keyName:'VCO freq (GHz)', if changed,
    # Delete invalid line with error message
    macro_info = macro_info[~ macro_info['VCO freq (GHz)'].isin(["Error"])]
    x = pd.DataFrame(macro_info.iloc[:, :])

    # Delete 重复行,并重新写入'MacroInfo_cared_PLL0_demo.xlsx'
    x.drop_duplicates(keep='first', inplace=True)
    path_simple = os.path.join(OutputPath, 'MacroInfo_cared_PLL0_simple.xlsx')
    x.to_excel(path_simple, header=1, index=False, encoding='utf-8', sheet_name='frequency_plan')

    # if PLL0 exist
    pll1Path = os.path.join(OutputPath, 'MacroInfo_cared_PLL1.xlsx')
    if (os.path.exists(pll1Path)):
        macro_info_PLL1 = pd.read_excel(pll1Path, sheet_name="frequency_plan", dtype=str, keep_default_na=False,
                                        header=0)
        macro_info_PLL1 = macro_info_PLL1[~macro_info_PLL1['VCO freq (GHz)'].isin(["Error"])]
        y = pd.DataFrame(macro_info_PLL1.iloc[:, :])
        if y.empty:
            print('PLL1 info is empty')
        else:
            print('PLL1 info is existed')

        # Delete 重复行,并重新写入'MacroInfo_cared_PLL0_demo.xlsx'
        y.drop_duplicates(keep='first', inplace=True)
        path_simple = os.path.join(OutputPath, 'MacroInfo_cared_PLL1_simple.xlsx')
        y.to_excel(path_simple, header=1, index=False, encoding='utf-8', sheet_name='frequency_plan')


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/759890
推荐阅读
相关标签
  

闽ICP备14008679号