-2

This question was monopolized and downvoted by someone who didn't understand it in the first place. The answer provided was provocative, vainly verbose and deliberately misleading. Considering my question could not be deleted, I decided to erase its content and posted a new one instead.

Fortunately, I have been provided with a much more indulgent and courteous answer.

solub
  • 1,291
  • 17
  • 40
  • What is `df`? Please read [mcve] and [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – ImportanceOfBeingErnest Nov 07 '17 at 12:48
  • Did you read the two links I gave you? It is not enough to know that `df` denotes a DataFrame. – ImportanceOfBeingErnest Nov 07 '17 at 13:53
  • 2
    We realise what `df` means, what @ImportanceOfBeingErnest probably means is that what does `df` _look_ like. I.e. provide some code that has some fake data that reproduces the problem so that we can run it on our machines. In other words a [MCVE](https://stackoverflow.com/help/mcve). – DavidG Nov 07 '17 at 16:48
  • @DavidG Actually you can never be sure. So just to show that if `df` wasn't a dataframe, the code from the question could actually work, I added a nonsensical answer. – ImportanceOfBeingErnest Nov 07 '17 at 17:30

1 Answers1

1

This is to show why verifiable examples are needed.

One could surely think of a datastructure where the code from the question actually produces the desired result, as seen in the following.

import numpy as np; np.random.seed(1)
import matplotlib.pyplot as plt

class C(list):
    def __init__(self, l):
        self.curr = 0
        list.__init__(self, l)
        self.get = list.__getitem__

    def plot(self, kind, color):
        plt.bar(range(len(self)), self, color=color)

    def __getitem__(self,index):
        self.curr = self.index(index)
        return self

    def count(self):
        return self.get(self,self.curr)


df = C(list(np.random.rand(15)*80000))    

# unchanged code from the question      
df.plot(kind='bar', color=['powderblue' if df[e].count() < 40000 else 'red' for e in df])

plt.show()

enter image description here

Hence it is important to clearify what is what by providing a mcve.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712