vba 使用 CSV 文件的最小学习曲线语言
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3339403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Smallest learning curve language to work with CSV files
提问by l--''''''---------''''''''''''
VBA is not cutting it for me anymore. I have lots of huge Excel files to which I need to make lots of calculations and break them down into other Excel/CSV files.
VBA 不再为我切割了。我有很多巨大的 Excel 文件,我需要对其进行大量计算并将它们分解为其他 Excel/CSV 文件。
I need a language that I can pick up within the next couple of days to do what I need, because it is kind of an emergency. I have been suggested python, but I would like to check with you if there is anything else that does CSV file handling quickly and easily.
我需要一种我可以在接下来的几天内学会的语言来做我需要的事情,因为这是一种紧急情况。有人建议我使用 python,但我想与您确认是否还有其他任何东西可以快速轻松地处理 CSV 文件。
采纳答案by ssegvic
回答by Chris B.
Python is an excellent choice. The csv
module makes reading and writing CSV files easy (even Microsoft's, uh, "idiosyncratic" version) and Python syntax is a breeze to pick up.
Python 是一个很好的选择。该csv
模块使读取和写入 CSV 文件变得容易(即使是微软的,呃,“特殊”版本),而且 Python 语法很容易上手。
I'd actually recommend againstPerl, if you're coming to it fresh. While Perl is certainly powerful and fast, it's often cryptic to the point of incomprehensible to the uninitiated.
其实我建议对Perl的,如果你新鲜的来了。虽然 Perl 确实强大且快速,但它通常是神秘的,以至于外行人无法理解。
回答by nico
What kind of calculation you have to do? Maybe Rwould be an alternative?
你需要做什么样的计算?也许R会是一个选择?
EDIT: just to give a few basic examples
编辑:只是举几个基本的例子
# Basic usage
data <- read.csv("myfile.csv")
# Pipe-separated values
data <- read.csv("myfile.csv", sep="|")
# File with header (columns will be named as header)
data <- read.csv("myfile.csv", header=TRUE)
# Skip the first 5 lines of the file
data <- read.csv("myfile.csv", skip=5)
# Read only 100 lines
data <- read.csv("myfile.csv", nrows=100)
回答by John Howard
Python definitely has a small learning curve, and works with csv files well
Python 的学习曲线肯定很小,并且可以很好地处理 csv 文件
回答by rebelliard
You know VBA? Why not Visual Basic 2008 / 2010, or perhaps C#? I'm sure languages like python and ruby would be relatively easier for the job, but you're already accustomed to the ".NET way" of doing things, so it makes sense to keep working with them instead of learning a whole new thing just for this job.
你知道 VBA 吗?为什么不是 Visual Basic 2008 / 2010,或者 C#?我相信像 python 和 ruby 这样的语言会相对容易一些,但你已经习惯了“.NET 方式”的做事方式,所以继续使用它们而不是学习全新的东西是有意义的只为这份工作。
Using C#:
使用 C#:
var csvlines = File.ReadAllLines("file.csv");
var query = from csvline in csvlines
let data = csvline.Split(',')
select new
{
ID = data[0],
FirstName = data[1],
LastName = data[2],
Email = data[3]
};
回答by John Machin
You say you have "excelfiles to which i need to make lots of calculations and break them down into other excel/csv files" but all the answers so far talk about csv only ...
你说你有“擅长,而我需要做大量的计算,并把它们分解成其他文件的Excel/ CSV文件”,但所有的答案到目前为止谈论仅CSV ...
Python has a csv read/write module as others have mentioned. There are also 3rd party modules xlrd
(reads) and xlwt
(writes) modules for XLS files. See the tutorial on this site.
正如其他人提到的,Python 有一个 csv 读/写模块。还有用于 XLS 文件的3rd 方模块xlrd
(读取)和xlwt
(写入)模块。请参阅此站点上的教程。
回答by Dan Breslau
I'd give awka try. If you're running windows, you can get awk via the cygwin utilities.
我想试试awk。如果您正在运行 Windows,则可以通过cygwin 实用程序获得 awk 。
回答by T.E.D.
This may not be anybody's popular language du-jour, but since CSV files are line-oriented and split into fields, dealing with them is just about the perfect application for awk. It was built for processing line oriented text data that can be split into fields.
这可能不是任何人的流行语言 du-jour,但由于 CSV 文件是面向行的并分为多个字段,因此处理它们几乎是awk的完美应用程序。它是为处理可以拆分为字段的面向行的文本数据而构建的。
Most of the other languages folks are going to reccomend will be much more general-purpose, so there's going to be a lot more in them that isn't nessecarily applicable to processing line-oriented text data.
人们会推荐的大多数其他语言将更加通用,因此它们中会有更多的语言不适用于处理面向行的文本数据。
回答by chimeracoder
That depends on what you want to do with the files.
这取决于您想对文件做什么。
Python's learning curve is less steep than R's. However, R has a bunch of built-in functions that make it very well suited for manipulating .csv files easily, particularly for statistical purposes.
Python 的学习曲线不如 R 陡峭。然而,R 有一堆内置函数,使其非常适合轻松操作 .csv 文件,特别是用于统计目的。
Edit:I'd recommend R over Python for this purpose alone, if only because the basic operations (reading files, dropping rows, dropping columns, etc.) are slightly faster to write in R than in Python.
编辑:仅出于此目的,我建议使用 R 而不是 Python,这仅仅是因为在 R 中编写基本操作(读取文件、删除行、删除列等)比在 Python 中编写稍快。
回答by Hut8
Perl is surprisingly efficient for a scripting language for text. cpan.org has a tremendous number of modules for dealing with CSV data. I've also both written and wrote data in XLS format with another Perl module. If you were able to use VBA, you can certainly learn Perl (the basics of Perl are easy, though it's just as easy for you or others to write terse yet cryptic code).
Perl 对于文本脚本语言来说非常高效。cpan.org 有大量用于处理 CSV 数据的模块。我还使用另一个 Perl 模块以 XLS 格式写入和写入数据。如果您能够使用 VBA,您当然可以学习 Perl(Perl 的基础知识很容易,尽管您或其他人编写简洁而神秘的代码同样容易)。