带有大数据的 Seaborn 直方图 [英] Seaborn histogram with bigdata

查看:47
本文介绍了带有大数据的 Seaborn 直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制一个包含 300 万行(我有 2CPU/16GB RAM)的大数据集的不错的直方图.尽管我提供了垃圾箱,但我从来没有得到一个情节.是否有更有效的方法来绘制直方图?请参阅下面的代码.

I am trying to plot a nice histogram of a big dataset of 3 mln rows (I have 2CPUs/16GB RAM). Even though I provided bins, I never got a plot. Is there more efficient method to plot a histogram? See the code below.

df0 = dd.read_csv(filename, sep="|", header=None, dtype=np.str, error_bad_lines=False, usecols=col0, quoting=3, encoding='ISO-8859-1')
dfs = df0[df0['DocumentTypeStndCode']=='D'].compute()
dfs['Price'] = dfs[pd.to_numeric(dfs['Price'], errors='coerce').notnull()]

sns.distplot(dfs['Price'], bins=[0, 10000, 200000, 400000, 2000000], kde=False)
plt.show()

推荐答案

这对您来说应该不是问题.我展示了几秒钟来生成给定 5000 万行的图.我先尝试了 pandas hist.

This shouldn't be a problem for you. I'm showing a couple seconds to generate the plots given 50 million rows. I tried pandas hist first.

import pandas as pd
import numpy as np
%matplotlib inline
df = pd.DataFrame({
  'values': np.random.beta(0.5, 0.1, size=50000000)
})
hist = df.hist(bins=10)

和seaborn一样

import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

sns.distplot(df['values'], bins=[0, .10000, .200000, .400000, 2.000000], kde=False)
plt.show()

这篇关于带有大数据的 Seaborn 直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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