【发布时间】:2016-10-04 15:36:15
【问题描述】:
我有一个包含 7000 行的大型数据文件(虽然不是很大!),如下所示:
# data can be obtained from pastebin
# filename = input.csv
# lots of comments
# wave flux err
0.807172 7.61973e-11 1.18177e-13
0.807375 7.58666e-11 1.18288e-13
0.807577 7.62136e-11 1.18504e-13
0.80778 7.64491e-11 1.19389e-13
0.807982 7.62858e-11 1.18685e-13
0.808185 7.63852e-11 1.19324e-13
0.808387 7.60547e-11 1.18952e-13
0.80859 7.52287e-11 1.18016e-13
0.808792 7.53114e-11 1.18979e-13
0.808995 7.58247e-11 1.20198e-13
# lots of other lines
输入数据的链接:http://pastebin.com/KCW9phzX
我想提取 0.807375 和 0.807982 之间波长的数据。
使输出看起来像这样:
#filename = output.csv
0.807375 7.58666e-11 1.18288e-13
0.807577 7.62136e-11 1.18504e-13
0.80778 7.64491e-11 1.19389e-13
0.807982 7.62858e-11 1.18685e-13
类似链接如下:
https://stackoverflow.com/questions/8956832/python-out-of-memory-on-large-csv-file-numpy/8964779#=
efficient way to extract few lines of data from a large csv data file in python
What is the most efficient way to match list items to lines in a large file in Python?
Extract specific lines from file and create sections of data in python
how to extract elements from a list in python?
How to use numpy.genfromtxt when first column is string and the remaining columns are numbers?
genfromtxt and numpy
【问题讨论】:
-
如果您对 numpy/pandas 感到满意,您可以看看 Dask,它是较新的 Blaze 项目的一部分 - 它专门设计用于处理不适合内存的数据集。 matthewrocklin.com/blog/work/2016/02/22/dask-distributed-part-2
-
文件有多大?几行?您想要
numpy解决方案还是非numpy解决方案? -
在使用二进制搜索查找所需行的范围时,尽可能少地解析文件的行。 Numpy 在这里帮不了你太多。
-
@wwii 现在文件是 6700 行,但是,我必须处理天文数据(我是一名天文学学生),所以欢迎 numpy 和非 numpy 的答案!跨度>
标签: python csv numpy pandas memory