zoukankan      html  css  js  c++  java
  • python操作csv,对比两个csv文件某列值

    功能:

    对比两个csv文件中的某列值,csv文件1中存在,文件2中不存在。

    #!/usr/bin/env python
    #-- encoding:utf-8 --
    
    import csv
     
    all_list = []
    agent_list = []
    def ecsInsAll():
      with open('/Documents/egion_2020.csv', 'U') as csvfile:
        reader = csv.DictReader(csvfile)
        all_list = [row["private_ip"] for row in reader]
      return all_list
    
    def agentAll():
      with open('/Documents/sqlResult.csv', 'U') as csvfile:
        reader = csv.DictReader(csvfile)
        agent_list = [row["ipAddress"] for row in reader]
      return agent_list
      
    
    if __name__ == '__main__':
      all_list = ecsInsAll()
      agent_list = agentAll()
      print "阿里云ECS机器总数:",len(all_list)
      print "已经安装agent机器总数:",len(agent_list)
      e = [y for y in all_list if y not in agent_list]  #在c_list列表中而不在all_list列表中
      # print '没有安装agent的机器IP:',len(e),e
      print '没有安装agent的机器IP,总数:',len(e)
      i = 1;
      for name in e:
        # print name
        with open('/Documents/list_all_region_2020.csv', 'U') as csvfile:
          reader = csv.DictReader(csvfile)
          for row in reader:
            if name == row["private_ip"]:
              print i,row["private_ip"],row["Region"]
              i=i+1
              
  • 相关阅读:
    redis 安装配置
    ORM 效率补充
    function*
    路由器
    nodejs开发辅助工具nodemon
    npm淘宝镜像配置
    Node中的模块系统
    artTemplate不仅可以在浏览器中使用,还可以在node中使用
    代码风格JavaScript standard style与Airbnb style
    osChina.net工具
  • 原文地址:https://www.cnblogs.com/husbandmen/p/13536221.html
Copyright © 2011-2022 走看看