Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Toy example. First make a <code>datetime</code> index. Here I make an index using two days repeated 10 times each. I then make some dummy data using <code>randn</code>.</p> <pre><code>In [1]: date_index = [datetime(2012,01,01)] * 10 + [datetime(2013,01,01)] * 10 In [2]: df = DataFrame({'A':randn(20),'B':randn(20)}, index=date_index) In [3]: df Out[3]: A B 2012-01-01 -1.155124 1.018059 2012-01-01 -0.312090 -1.083568 2012-01-01 0.688247 -1.296995 2012-01-01 -0.205218 0.837194 2012-01-01 0.700611 -0.001015 2012-01-01 1.996796 -0.914564 2012-01-01 -2.268237 0.517232 2012-01-01 -0.170778 -0.143245 2012-01-01 -0.826039 0.581035 2012-01-01 -0.351097 -0.013259 2013-01-01 -0.767911 -0.009232 2013-01-01 -0.322831 -1.384785 2013-01-01 0.300160 0.334018 2013-01-01 -1.406878 -2.275123 2013-01-01 1.722454 0.873262 2013-01-01 0.635711 -1.763352 2013-01-01 -0.816891 -0.451424 2013-01-01 -0.808629 -0.092290 2013-01-01 0.386046 -1.297096 2013-01-01 0.261837 0.562373 </code></pre> <p>If I understand your question correctly, you want to decile <em>within</em> each date. To do that, you can first move the index into the dataframe as a column. Then, you can groupby by the new column (here it's called index), and use <code>transform</code> with a lambda function. The lambda function below, applies <code>pandas.qcut</code> to the grouped <code>series</code> and returns the <code>labels</code> attribute.</p> <pre><code>In [4]: df.reset_index().groupby('index').transform(lambda x: qcut(x,10).labels) Out[4]: A B 0 1 9 1 4 1 2 7 0 3 5 8 4 8 5 5 9 2 6 0 6 7 6 3 8 2 7 9 3 4 10 3 6 11 4 2 12 6 7 13 0 0 14 9 9 15 8 1 16 1 4 17 2 5 18 7 3 19 5 8 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload