Horizontal Bar Chart on Pandas Data Frame with Dynamic Column Names
<p>I have the following source data (which comes from a csv file):</p>

<pre><code>ABC,2016-6-9 0:00,95,"{'//Purple': [115L], '//Yellow': [403L], '//Blue': [16L], '//White-XYZ': [0L]}"
ABC,2016-6-10 0:00,0,"{'//Purple': [219L], '//Yellow': [381L], '//Blue': [90L], '//White-XYZ': [0L]}"
ABC,2016-6-11 0:00,0,"{'//Purple': [817L], '//Yellow': [21L], '//Blue': [31L], '//White-XYZ': [0L]}"
ABC,2016-6-12 0:00,0,"{'//Purple': [80L], '//Yellow': [2011L], '//Blue': [8888L], '//White-XYZ': [0L]}"
ABC,2016-6-13 0:00,0,"{'//Purple': [32L], '//Yellow': [15L], '//Blue': [4L], '//White-XYZ': [0L]}"
DEF,2016-6-16 0:00,0,"{'//Purple': [32L], '//Black': [15L], '//Pink': [4L], '//NPO-Green': [3L]}"
DEF,2016-6-17 0:00,0,"{'//Purple': [32L], '//Black': [15L], '//Pink': [4L], '//NPO-Green': [0L]}"
DEF,2016-6-18 0:00,0,"{'//Purple': [32L], '//Black': [15L], '//Pink': [4L], '//NPO-Green': [7L]}"
DEF,2016-6-19 0:00,0,"{'//Purple': [32L], '//Black': [15L], '//Pink': [4L], '//NPO-Green': [14L]}"
DEF,2016-6-20 0:00,0,"{'//Purple': [32L], '//Black': [15L], '//Pink': [4L], '//NPO-Green': [21L]}"
</code></pre>

<p>I use <a href="http://stackoverflow.com/questions/39928273/how-to-remove-curly-braces-apostrophes-and-square-brackets-from-dictionaries-in">How to remove curly braces, apostrophes and square brackets from dictionaries in a Pandas dataframe (Python)</a> to transform that data into a Data Frame that I can use to plot certain variables.  The Data Frame looks as follows (note: not the same data as what's in the source csv file, but the structure is the same):</p>

<pre><code>   Company   Date         Code       Yellow     Blue        White      Black

0  ABC       2016-6-9     115        403         16         19         472     
1  ABC       2016-6-10    219        381         90         20         2474
2  ABC       2016-6-11    817        21          31         88         54
3  ABC       2016-6-12    80         2011        8888       0          21
4  ABC       2016-6-13    21         15          46         20         56
5  DEF       2016-6-16    64         42          76         4          41
6  DEF       2016-6-17    694        13          84         50         986
7  DEF       2016-6-18    325        485         38         60         174
8  DEF       2016-6-19    418        35          174        251        11
9  DEF       2016-6-20    50         56          59         19         03
</code></pre>

<p>I need to create several time series plots of the colors (which I can do very easily, given the way that the data frame is constructed).  </p>

<p>But, I also want to be able to make a horizontal bar plot <strong>as of a specific date</strong> (see <a href="https://stanford.edu/~mwaskom/software/seaborn/examples/horizontal_barplot.html" rel="nofollow">https://stanford.edu/~mwaskom/software/seaborn/examples/horizontal_barplot.html</a> for an example).</p>

<p>For instance, using my data, as of June 9, 2016, the bar plot would look as follows (not to scale):</p>

<pre><code>Black:    ********************************

Yellow:   **************************

White:    ***

Blue:     **
</code></pre>

<p>The problem I'm having is that the column names (e.g. 'yellow', 'blue', 'white' and 'black') can change, as can the number of columns.</p>

<p>Does anyone know if it is possible to loop through a certain number of columns <strong>to the right</strong> of the 'Code' column and then use those to create a horizontal bar chart similar to what's above?  Or, perhaps take a slice of the data to the right of the 'Code' column?  </p>

<p>Or, does the Data Frame itself need to be structured differently such that it can be used to make both a time series plot and a horizontal bar chart?</p>

<p>Thanks!</p>

<p>in order to loop through a certain number of columns to the right of the 'code' column I would do something of the form</p>

<pre><code>for col in df.columns[3:]:
    plot(col)
</code></pre>

<p>However this only works if you can guarantee that your columns will always be in the same order. Alternatively you could make sure that the columns of interest for that particular chart are named in a systematic way.</p>

<p>Hope this helps!</p>

python pandas matplotlib plot seaborn