如何使用 Python 脚本从 CSV 文件中过滤 [英] How to Filter from CSV file using Python Script
本文介绍了如何使用 Python 脚本从 CSV 文件中过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有包含三列的 abx.csv 文件.我想过滤具有 Application
作为 Central
的数据并将其写入同一个 .csv 文件
I have abx.csv file having three columns. I would like to filter the data which is having Application
as Central
and write it in same .csv file
User ID Name Application
001 Ajohns ABI
002 Fjerry Central
900 Xknight RFC
300 JollK QDI
078 Demik Central
我需要在同一个 .csv 文件的三列中写入 User ID,Name,Apllication
(修改现有文件)
I need to write User ID,Name,Apllication
in three column in same .csv file (modifying the existing file)
推荐答案
import csv
reader = csv.reader(open(r"abx.csv"),delimiter=' ')
filtered = filter(lambda p: 'Central' == p[2], reader)
csv.writer(open(r"abx.csv",'w'),delimiter=' ').writerows(filtered)
这篇关于如何使用 Python 脚本从 CSV 文件中过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文