简体   繁体   English

Python 2.7,Excel.csv获取特定列&…?

[英]Python 2.7, Excel.csv getting specific columns &…?

Sorry , guys If there is a post similar or exactly like this. 抱歉 ,伙计们,如果有类似或类似的帖子。 I'm new to programming/coding and just couldn't find a similar post. 我是编程/编码新手,却找不到类似的帖子。 What I'm trying to do is a script that takes a keyword/input from the user and from that keyword the program will find all columns in the excel.csv data. 我正在尝试做的是一个脚本,该脚本从用户那里获取关键字/输入,并且该程序将从该关键字中找到excel.csv数据中的所有列。 Then make a copy of the column/s to a new excel file . 然后将列副本复制到新的excel文件中 This is with the intention of working with large excel files. 这样做是为了处理大型excel文件。 Is there any tutorials or a place where I can find even tips/hints/Examples of how to do this? 是否有任何教程或地方甚至可以找到提示/提示/如何执行此操作的示例? Thanks for your time and comprehension. 感谢您的时间和理解。

Again is just: 再次只是:

  1. Name of the file to be read. 要读取的文件名。
  2. keyword which identify columns to be saved/copy/cut. 关键字,标识要保存/复制/剪切的列。
  3. Create new file then paste + truncate? 创建新文件,然后粘贴+截断?

    ( Anything close to this or a tutorials/examples would be truly appreciated. ) 任何接近于此或教程/示例的内容都将受到感激。

Sincerely, A novice. 真诚的,新手。

Here you go.. 干得好..

>>> import csv
>>> with open('eggs.csv', 'rb') as csvfile:
...     spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
...     for row in spamreader:
...         print ', '.join(row)
Spam, Spam, Spam, Spam, Spam, Baked Beans
Spam, Lovely Spam, Wonderful Spam

Hope this will give you some idea... 希望这会给你一些想法...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM