2

I have multiple csv files that I want to manipulate(calculate mean, sum, etc.) and after that I want to store them in a SQLite database.

But I want to know what is the most proper way to do that.

CSV to SQL and manipulate with Pandas

OR

CSV, manipulate with Pandas and store in SQL

For example, I want to store all the data in this table http://financials.morningstar.com/ratios/r.html?t=GOOG&region=USA&culture=en-US. I will update yearly and add 2013,2014,etc. In my SQL table. I'll create a column where I will have 10 year average for each rows, etc.

Regards,

4

1 回答 1

2

目前,pandas 对操作 CSV 文件的支持远远超出了操作 SQL 数据库的能力,尽管现在有很大的努力来突飞猛进地改进后者!

看看文档_ read_csv这是用于数据分析应用程序的最灵活、最快速且功能最强大的文本文件读取器/写入器之一。

另一方面read_sql,只能写入sqlite数据库而不存储index.

read_csv您甚至可以读取对象(MultiIndex分层索引)!

如果您没有绑定到数据库,那么我建议您考虑使用 pandasHDF5来实现持久性。我一直在使用它,而且效果很好。

总之,如果您必须使用数据库,我会推荐您列出的第一选择,因为除非您正在使用,否则向数据库写入任何内容都行不通sqlite,但您可以从其他人那里读取sqlite

于 2013-08-08T02:09:13.650 回答