从字典创建一个dask数据框 [英] create a dask dataframe from a dictionary

查看:119
本文介绍了从字典创建一个dask数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一本这样的字典:

d = {'Caps': 'cap_list', 'Term': 'unique_tokens', 'LocalFreq': 'local_freq_list','CorpusFreq': 'corpus_freq_list'}

我想要从中创建一个dask数据框。我该怎么做?通常,在Pandas中,可以通过以下方式轻松将其导入到Pandas df:

I want to create a dask dataframe from it. How do I do it? Normally, in Pandas, is can be easily imported to a Pandas df by:

df = pd.DataFrame({'Caps': cap_list, 'Term': unique_tokens, 'LocalFreq': local_freq_list,
                               'CorpusFreq': corpus_freq_list})

我应该先装入一个袋子,然后再从袋子转换为ddf吗?

Should I first load into a bag and then convert from bag to ddf?

推荐答案

如果您的数据适合记忆,然后鼓励您使用Pandas代替Dask Dataframe。

If your data fits in memory then I encourage you to use Pandas instead of Dask Dataframe.

如果出于某些原因您仍想使用Dask数据框,则可以将其转换为Pandas数据框,然后使用 dask.dataframe.from_pandas 函数。

If for some reason you still want to use Dask dataframe then I would convert things to a Pandas dataframe and then use the dask.dataframe.from_pandas function.

import dask.dataframe as dd
import pandas as pd

df = pd.DataFrame(...)
ddf = dd.from_pandas(df, npartitions=20)

但是在很多情况下,这比仅使用熊猫慢一些。

But there are many cases where this will be slower than just using Pandas well.

这篇关于从字典创建一个dask数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆