import\u0020pandas\u0020as\u0020pd\nimport\u0020sys\n\n#\u0020从参数 1 获取文件名\nfilename\u0020=\u0020sys.argv[1]\n\n#\u0020读取查询条件文件\nwith\u0020open(filename,\u0020'r')\u0020as\u0020file:\n\u0020\u0020query_conditions\u0020=\u0020file.readlines()\nquery_conditions\u0020=\u0020[condition.strip()\u0020for\u0020condition\u0020in\u0020query_conditions]\n\n#\u0020读取 results-20230616T1300.csv 文件\ndf\u0020=\u0020pd.read_csv('results-20230616T1300.csv')\n\n#\u0020使用集合实现查询并打印结果\nfor\u0020condition\u0020in\u0020query_conditions:\n\u0020\u0020result\u0020=\u0020df[df['id']\u0020==\u0020condition]\n\u0020\u0020if\u0020not\u0020result.empty:\n\u0020\u0020\u0020\u0020print(result[['id',\u0020'text']])

Python 脚本:使用 Pandas 和集合从文本文件查询 CSV 数据

原文地址: https://www.cveoy.top/t/topic/pWsY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录