Python pandas empty correlation matrix -
i running python 2.7.6, pandas 0.13.1. unable compute correlation matrix dataframe, , i'm not sure why. here example dataframe:
in [24]: foo out[24]: b c 2011-10-12 0.006204908 -0.0009503677 0.003480105 2011-10-13 0.00234903 -0.0005122284 -0.001738786 2011-10-14 0.01045599 0.000346268 0.002378351 2011-10-17 0.003239088 0.001246239 -0.002651856 2011-10-18 0.001717674 -0.0001738079 0.002013923 2011-10-19 0.0001919342 6.399505e-05 -0.001311259 2011-10-20 0.0007430615 0.001186141 0.001919222 2011-10-21 -0.01075129 -0.0015123 0.000807017 2011-10-24 -0.00819597 -0.0005124197 0.003037654 2011-10-25 -0.01604287 0.001157013 -0.001227516 [10 rows x 3 columns] now i'll try compute correlation:
in [27]: foo.corr() out[27]: empty dataframe columns: [] index: [] [0 rows x 0 columns] on other hand, can compute correlations of each column each other column. example:
in [31]: foo['a'].corr(foo['b']) out[31]: 0.048578514633405255 any idea might causing issue? lot.
version info
in [34]: import pandas pd in [35]: pd.__version__ out[35]: '0.13.1'
as jeff mentioned in comments, problem resulted columns having object dtype. future reference, if object looks numeric, check dtype , make sure numeric (e.g. foo.astype(float)) before computing correlation matrix.
Comments
Post a Comment