Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn sorted indexes skipping nan values in pandas?
    primarykey
    data
    text
    <p>I have the following data set:</p> <pre><code>PID,RUN_START_DATE,PUSHUP_START_DATE,SITUP_START_DATE,PULLUP_START_DATE 1,2013-01-24,2013-01-02,,2013-02-03 2,2013-01-30,2013-01-21,2013-01-13,2013-01-06 3,2013-01-29,2013-01-28,2013-01-01,2013-01-29 4,2013-02-16,2013-02-12,2013-01-04,2013-02-11 5,2013-01-06,2013-02-07,2013-02-25,2013-02-12 6,2013-01-26,2013-01-28,2013-02-12,2013-01-10 7,2013-01-26,,2013-01-12,2013-01-30 8,2013-01-03,2013-01-24,2013-01-19,2013-01-02 9,2013-01-22,2013-01-13,2013-02-03, 10,2013-02-06,2013-01-16,2013-02-07,2013-01-11 </code></pre> <p>I know I can use <code>numpy.argsort</code> to return the sorted indexes of the values: </p> <pre><code>SQ_AL_INDX = numpy.argsort(df_sequence[['RUN_START_DATE', 'PUSHUP_START_DATE', 'SITUP_START_DATE', 'PULLUP_START_DATE']], axis=1) </code></pre> <p>...returns...</p> <pre><code> RUN_START_DATE PUSHUP_START_DATE SITUP_START_DATE PULLUP_START_DATE 0 2 1 0 3 1 3 2 1 0 2 2 1 0 3 3 2 3 1 0 4 0 1 3 2 5 3 0 1 2 6 1 2 0 3 7 3 0 2 1 8 3 1 0 2 9 3 1 0 2 </code></pre> <p>But, it seems to put <code>pandas.NaT</code> values into the first position. So in this example <code>where PID == 1</code> the sort order returns <code>2 1 0 3</code>. But, the second index position is a <code>pandas.Nat</code> value.</p> <p>How can I get the sorted indexes while skipping the <code>pandas.NaT</code> values (e.g., the return index values would be <code>2 1 np.NaN 3</code> or <code>2 1 pandas.NaT 3</code> or better yet <code>1 0 2</code> for <code>PID 1</code> instead of <code>2 1 0 3</code>)?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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