Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to plot a very large pandas dataframe?

I have a large pandas dataframe of shape (696, 20531) and I'd like to plot all of it's values in a histogram. Using the df.plot(kind='hist') seems to be taking forever. Is there a better way to do this?

like image 939
jp89 Avatar asked Feb 01 '16 06:02

jp89


Video Answer


1 Answers

Use DataFrame.stack():

import numpy as np
import pandas as pd
np.random.seed(0)
df = pd.DataFrame(np.random.randn(5, 10))
print(df.to_string())

          0         1         2         3         4         5         6         7         8         9
0 -0.760559  0.317021  0.325524 -0.300139  0.800688  0.221835 -1.258592  0.333504  0.669925  1.413210
1  0.082853  0.041539  0.255321 -0.112667 -1.224011 -0.361301 -0.177064  0.880430  0.188540 -0.318600
2 -0.827121  0.261817  0.817216 -1.330318 -2.254830  0.447037  0.294458  0.672659 -1.242452  0.071862
3  1.173998  0.032700 -0.165357  0.572287  0.288606  0.261885 -0.699968 -2.864314 -0.616054  0.798000
4  2.134925  0.966877 -1.204055  0.547440  0.164349  0.704485  1.450768 -0.842088  0.195857 -0.448882

df.stack().hist()

Histogram

like image 58
Stop harming Monica Avatar answered Nov 14 '22 22:11

Stop harming Monica