合并从 csv 文件导入的 Dask 数据帧
Merging Dask dataframes imported from csv files
我需要导入大型数据集并合并它们。我知道还有其他类似的问题,但我找不到针对我的问题的答案。看来 dask
我能够将大型数据集读入数据框,但无法将其与另一个数据框合并。
import dask.dataframe as dd
import pandas as pd
#I have to do this with dask since with pandas I get mem issue and kills the python
ps = dd.read_csv('*.dsv',sep='|',low_memory=False)
mx = dd.read_csv('test.csv',sep='|',low_memory=False)
# this is where I get the error
mg = pd.merge(ps,mx,left_on='ACTIVITY_ID',right_on='WONUM')
ValueError: can not merge DataFrame with instance of type <class 'dask.dataframe.core.DataFrame'>
很明显,它不能将 dask 数据帧与 pandas 数据帧合并,但我还能怎么做呢?我可以使用 pySpark 或任何其他方法吗?
@JohnE 是对的——Dask 数据帧有一个 merge method, which (not coincidentally) is very similar to the pandas one;所以,既然你似乎需要一个内部合并,你应该简单地做:
mg = ps.merge(mx,left_on='ACTIVITY_ID',right_on='WONUM') # how='inner' by default, just as in pandas
如果您想将 Dask 数据帧转换为 pandas 数据帧,Dask from_pandas
method 也可能有用。
我需要导入大型数据集并合并它们。我知道还有其他类似的问题,但我找不到针对我的问题的答案。看来 dask
我能够将大型数据集读入数据框,但无法将其与另一个数据框合并。
import dask.dataframe as dd
import pandas as pd
#I have to do this with dask since with pandas I get mem issue and kills the python
ps = dd.read_csv('*.dsv',sep='|',low_memory=False)
mx = dd.read_csv('test.csv',sep='|',low_memory=False)
# this is where I get the error
mg = pd.merge(ps,mx,left_on='ACTIVITY_ID',right_on='WONUM')
ValueError: can not merge DataFrame with instance of type <class 'dask.dataframe.core.DataFrame'>
很明显,它不能将 dask 数据帧与 pandas 数据帧合并,但我还能怎么做呢?我可以使用 pySpark 或任何其他方法吗?
@JohnE 是对的——Dask 数据帧有一个 merge method, which (not coincidentally) is very similar to the pandas one;所以,既然你似乎需要一个内部合并,你应该简单地做:
mg = ps.merge(mx,left_on='ACTIVITY_ID',right_on='WONUM') # how='inner' by default, just as in pandas
如果您想将 Dask 数据帧转换为 pandas 数据帧,Dask from_pandas
method 也可能有用。