A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
| #!/bin/bash | |
| # | |
| # Copyright 2015 James Cheese | |
| # You may do anything with this work that copyright law would normally | |
| # restrict, so long as you retain the above notice(s) and this license | |
| # in all redistributed copies and derived works. There is no warranty. | |
| # | |
| # Python 3 Upgrade for Django Droplet | |
| # Will update the "Django on 14.04" Digital Ocean image. | |
| # Run as root. |
A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
| def shannon_entropy(img): | |
| # calculate the shannon entropy for an image | |
| histogram = img.histogram() | |
| histogram_length = sum(histogram) | |
| samples_probability = [float(h) / histogram_length for h in histogram] | |
| return -sum([p * math.log(p, 2) for p in samples_probability if p != 0]) |