的方法可以通过以下步骤实现:
import csv
with open('search.csv', 'r') as search_file:
search_reader = csv.reader(search_file)
search_data = list(search_reader)
with open('write.csv', 'w', newline='') as write_file:
write_writer = csv.writer(write_file)
for row in search_data:
if row[column_index] == 'search_string':
write_writer.writerow(row)
其中,column_index
是要搜索的列的索引,search_string
是要搜索的字符串。
完整的代码示例:
import csv
with open('search.csv', 'r') as search_file:
search_reader = csv.reader(search_file)
search_data = list(search_reader)
with open('write.csv', 'w', newline='') as write_file:
write_writer = csv.writer(write_file)
for row in search_data:
if row[column_index] == 'search_string':
write_writer.writerow(row)
这个方法适用于需要在一个csv文件中搜索特定字符串,并将匹配的行写入另一个csv文件的场景。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云