Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 非常大的CSV文件-如何只读取数据帧中的某些行_Python_Pandas_Csv_Machine Learning_Dask - Fatal编程技术网

Python 非常大的CSV文件-如何只读取数据帧中的某些行

Python 非常大的CSV文件-如何只读取数据帧中的某些行,python,pandas,csv,machine-learning,dask,Python,Pandas,Csv,Machine Learning,Dask,我有一个非常大的csv文件,无法使用pandas read_csv加载到我的计算机内存中 我将dask.dataframe视为dd 我需要使用dask从csv文件中只读取特定列的特定行,并将其存储为熊猫数据帧 例如: User ProductA ProductB A 1 2 B 2 3 C 3 1 如何使用dask仅读取用户C的行和列ProductA? 作为数据帧的所需输出: User ProductA C

我有一个非常大的csv文件,无法使用pandas read_csv加载到我的计算机内存中

我将
dask.dataframe视为dd

我需要使用dask从csv文件中只读取特定列的特定行,并将其存储为熊猫数据帧

例如:

User  ProductA  ProductB
A     1         2
B     2         3
C     3         1
如何使用dask仅读取用户C的行和列ProductA?

作为数据帧的所需输出:

User  ProductA
C     3

您可以使用
dask.dataframe
read\u csv
功能进行过滤,然后将
df
转换为数据帧:

import dask.dataframe as dd
import pandas as pd

path2file = "yourpath.csv"
cols = ["User", "ProductA"]
# Be careful about the sep (check if it is ; or something else and add it to the
# function below as parameter if so
dataset = dd.read_csv(path2file, usecols=cols)
# Filter 
dataset = dataset.loc[dataset["User"]=="C"]), :]
dataset = dataset.compute()

你能显示原始csv吗?@anon01它有3200万行和25列,这也行。我最初的破解方法是使用pandas将大文件读入较小的csv文件块,然后使用这些较小的文件块提取用户