处理 CSV 文件的最小学习曲线语言

发布于 2024-09-11 04:18:30 字数 166 浏览 3 评论 0 原文

VBA 不再适合我了。我有很多巨大的 Excel 文件,我需要对其进行大量计算并将它们分解为其他 Excel/CSV 文件。

我需要一种可以在接下来的几天内学会的语言来完成我需要的事情,因为这是一种紧急情况。有人建议我使用 python,但我想咨询一下是否还有其他方法可以快速轻松地处理 CSV 文件。

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

我做我的改变 2024-09-18 04:18:30

Python 是一个很好的选择。 csv 模块使读取和写入 CSV 文件变得容易(甚至是微软的,呃,“特殊”版本),并且 Python 语法很容易掌握。

如果您刚刚接触 Perl,我实际上会推荐您使用 Perl。虽然 Perl 无疑是​​强大且快速的,但对于外行来说,它往往很神秘,难以理解。

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.

I'd actually recommend against Perl, 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.

魂牵梦绕锁你心扉 2024-09-18 04:18:30

你需要做什么样的计算?也许 R 会是一个替代方案?

编辑:仅举一些基本示例

# 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)

What kind of calculation you have to do? Maybe R would be an alternative?

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)
北笙凉宸 2024-09-18 04:18:30

有很多工具可以完成这项工作,但是,Python 可能是目前最好的工具。有一个特殊的模块用于处理 csv 文件。查看官方文档

There are many tools for the job, but yes, Python is perhaps the best these days. There is a special module for dealing with csv files. Check the official docs.

戏舞 2024-09-18 04:18:30

Python 的学习曲线肯定很小,并且可以很好地处理 csv 文件

Python definitely has a small learning curve, and works with csv files well

标点 2024-09-18 04:18:30

您说您有“excel 文件,我需要对其进行大量计算并将它们分解为其他 excel/csv 文件”,但到目前为止所有答案都在谈论 csv只是...

正如其他人提到的那样,Python 有一个 csv 读/写模块。还有用于 XLS 文件的第 3 方模块 xlrd(读取)和 xlwt(写入)模块。请参阅此网站上的教程

You say you have "excel files 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 ...

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.

哀由 2024-09-18 04:18:30

你知道VBA吗?为什么不是 Visual Basic 2008 / 2010,或者 C#?我确信像 python 和 ruby​​ 这样的语言会相对更容易完成这项工作,但你已经习惯了“.NET 方式”做事,所以继续使用它们而不是学习全新的东西是有意义的只是为了这份工作。

使用 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]
            };
  1. .NET:Linq to CSV 库
  2. .NET:使用 LINQ 读取 CSV
  3. Python:读取CSV文件

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.

Using 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]
            };
  1. .NET: Linq to CSV library.
  2. .NET: Read CSV with LINQ
  3. Python: Read CSV file
对岸观火 2024-09-18 04:18:30

Perl 作为文本脚本语言出奇地高效。 cpan.org 有大量用于处理 CSV 数据的模块。我还使用另一个 Perl 模块以 XLS 格式写入和写入数据。如果您能够使用 VBA,您当然可以学习 Perl(Perl 的基础知识很简单,尽管您或其他人编写简洁但神秘的代码也同样容易)。

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).

少年亿悲伤 2024-09-18 04:18:30

这取决于您想对文件执行什么操作。

Python 的学习曲线没有 R 的那么陡峭。然而,R 有许多内置函数,使其非常适合轻松操作 .csv 文件,特别是出于统计目的。

编辑:仅出于此目的,我建议使用 R 而不是 Python,因为在 R 中编写基本操作(读取文件、删除行、删除列等)比在 Python 中编写稍快一些。

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.

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.

江南烟雨〆相思醉 2024-09-18 04:18:30

我会尝试 awk 。如果您运行的是 Windows,则可以通过 cygwin 实用程序 获取 awk。

I'd give awk a try. If you're running windows, you can get awk via the cygwin utilities.

我喜欢麦丽素 2024-09-18 04:18:30

这可能不是任何人都流行的流行语言,但由于 CSV 文件是面向行的并分为多个字段,因此处理它们几乎是 awk。它是为处理可以拆分为字段的面向行的文本数据而构建的。

人们推荐的大多数其他语言都更加通用,因此其中会有更多内容不一定适用于处理面向行的文本数据。

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.

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.

习惯成性 2024-09-18 04:18:30

PowerShell 内置了 CSV 导入

语法很丑陋,如下所示死亡,但它的设计目的是对管理员比对程序员更有用——所以谁知道呢,你可能会喜欢它。

它应该是一种快速上手的语言,无论好坏。

PowerShell has CSV import built in.

The syntax is ugly as death, but it's designed to be useful for administrators more than for programmers -- so who knows, you might like it.

It's supposed to be a quick get-up-and-go language, for better and worse.

蹲墙角沉默 2024-09-18 04:18:30

我很惊讶没有人建议PowerQuery;它非常适合合并文件并将其导入到 Excel,可以很好地进行列计算,并且内置了一个很好的图形编辑器。适用于 csv 和 excel 文件,也适用于 SQL 数据库和您期望的大多数其他内容。我设法在一天内完成一些基本的清理和格式化工作并运行,也许几天后就开始编写我自己的函数(摆脱 GUI)

并且由于它只真正执行数据库工作,因此它有 几乎没有任何函数需要学习(实际的语言称为“米”)

I'm surprised nobody's suggested PowerQuery; it's perfect for consolidating and importing files to Excel, does column calculations nicely and has a good graphical editor built in. Works for csvs and excel files but also SQL databases and most other things you'd expect. I managed to get some basic cleaning and formatting stuff up and running in a day, maybe a few days to start writing my own functions (break free from the GUI)

And since it only really does database stuff, it's got barely any functions to learn (the actual language is called "M")

云淡风轻 2024-09-18 04:18:30

PHP 有几个易于使用的 csv 函数:
http://www.php.net/manual-lookup。 php?pattern=csv&lang=en

PHP has a couple of csv functions that are easy to use:
http://www.php.net/manual-lookup.php?pattern=csv&lang=en

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文