Home > Back-end >  Create a descending list of instances of different values in a pandas dataframe
Create a descending list of instances of different values in a pandas dataframe

Time:04-01

I need to filter through a pandas dataframe, and sort one of the columns, returning the number of instances of each value in descending order. I've been able to accomplish this using a dictionary and some other things, but it isn't being returned in pandas format, which is what I need. Apparently, there is a built-in pandas functionality that can do this? What would that be?

This is the tsv that becomes the pandas dataframe:

Patient_ID  Sample_ID   Sample_Tumor_Normal Proteomics_Tumor_Normal Country Histologic_Grade_FIGO   Myometrial_invasion_Specify Histologic_type Treatment_naive Tumor_purity    Path_Stage_Primary_Tumor-pT Path_Stage_Reg_Lymph_Nodes-pN   Clin_Stage_Dist_Mets-cM Path_Stage_Dist_Mets-pM tumor_Stage-Pathological    FIGO_stage  LVSI    BMI Age Diabetes    Race    Ethnicity   Gender  Tumor_Site  Tumor_Site_Other    Tumor_Focality  Tumor_Size_cm   Num_full_term_pregnancies
C3L-00006   S001    Tumor   Tumor   United States   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  1.0 38.88   64.0    No  White   Not-Hispanic or Latino  Female  Anterior endometrium        Unifocal    2.9 1
C3L-00008   S002    Tumor   Tumor   United States   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage IV    IA  0.0 39.76   58.0    No  White   Not-Hispanic or Latino  Female  Posterior endometrium       Unifocal    3.5 1
C3L-00032   S003    Tumor   Tumor   United States   FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 51.19   50.0    Yes White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior endometrium  Unifocal    4.5 4 or more
C3L-00090   S005    Tumor   Tumor   United States   FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 No pathologic evidence of distant metastasis    Stage I IA  0.0 32.69   75.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior endometrium  Unifocal    3.5 4 or more
C3L-00098   S006    Tumor   Tumor   United States       under 50 %  Serous  YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA      20.28   63.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Anterior  and Posterior endometrium Unifocal    6.0 2
C3L-00136   S007    Tumor   Tumor   United States   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 55.67   50.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior endometrium  Unifocal    4.5 3
C3L-00137   S008    Tumor   Tumor   Other_specify   FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  1.0 25.68   60.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Both anterior and posterior Unifocal    5.0 2
C3L-00139   S009    Tumor   Tumor   United States       50 % or more    Serous  YES Normal  pT3a (FIGO IIIA)    pNX cM0 Staging Incomplete  Stage III   IIIA    1.0 21.57   83.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Both anterior and posterior Unifocal    4.0 4 or more
C3L-00143   S010    Tumor   Tumor   United States   FIGO grade 1    Not identified  Endometrioid    YES Normal  pT1 (FIGO I)    pN0 cM0 Staging Incomplete  Stage I IA  0.0 34.26   69.0    Yes White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior endometrium  Unifocal    5.2 2
C3L-00145   S011    Tumor   Tumor   United States   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX Staging Incomplete  Staging Incomplete  Stage I IA  0.0 36.57   59.0    Yes White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior endometrium  Unifocal    4.7 3
C3L-00156   S012    Tumor   Tumor   United States   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 27.83   56.0    Yes White   Not-Hispanic or Latino  Female  Anterior endometrium        Unifocal    2.2 2
C3L-00161   S014    Tumor   Tumor   United States   FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pN0 Staging Incomplete  No pathologic evidence of distant metastasis    Stage I IB  1.0 68.39   46.0    No  White   Hispanic or Latino  Female  Other, specify  Anterior and Posterior Endometrium  Unifocal    7.0 2
C3L-00358   S016    Tumor   Tumor   United States       50 % or more    Serous  YES Normal  pT1b (FIGO IB)  pNX cM0 Staging Incomplete  Stage I IB  1.0 26.22   90.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Both anterior and posterior endometrium Unifocal    4.5 Unknown
C3L-00361   S017    Tumor   Tumor   United States   FIGO grade 1    Not identified  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 42.98   64.0    Yes White   Not-Hispanic or Latino  Female  Anterior endometrium        Unifocal    2.7 None
C3L-00362   S018    Tumor   Tumor   United States   FIGO grade 1    Not identified  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 55.86   38.0    Yes White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior endometrium  Unifocal    13.5    None
C3L-00413   S019    Tumor   Tumor   United States   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT2 (FIGO II)   pN0 cM0 Staging Incomplete  Stage II    II  0.0 42.19   60.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Both anterior and posterior Unifocal    3.2 3
C3L-00449   S020    Tumor   Tumor   United States   FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 27.82   59.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior endometrium  Unifocal    7.0 None
C3L-00563   S021    Tumor   Tumor   Other_specify   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 No pathologic evidence of distant metastasis    Stage I IA  0.0 34.72   62.0    Yes Asian   Not-Hispanic or Latino  Female  Other, specify  Both anterior and posterior Unifocal    3.0 1
C3L-00586   S022    Tumor   Tumor   United States   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT2 (FIGO II)   pN2 (FIGO IIIC2)    cM0 Staging Incomplete  Stage III   IIIC2   1.0 21.45   50.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Anterior and posterior endometrium  Unifocal    6.0 2
C3L-00601   S023    Tumor   Tumor   United States   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 25.03   57.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Both anterior and posterior Unifocal    3.5 3
C3L-00605   S024    Tumor   Tumor   United States   FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 No pathologic evidence of distant metastasis    Stage I IA  0.0 38.54   73.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior  Unifocal    2.7 Unknown
C3L-00767   S025    Tumor   Tumor   Other_specify   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 65.71   56.0    No  White   Not-Hispanic or Latino  Female  Anterior endometrium        Multifocal  2.3 4 or more
C3L-00769   S026    Tumor   Tumor   Other_specify   FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pN0 cM0 Staging Incomplete  Stage I IB  0.0 46.64   56.0    No  White   Not reported    Female  Anterior endometrium        Multifocal  4.5 2
C3L-00770   S027    Tumor   Tumor   Other_specify   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 45.83   73.0    Yes White   Not-Hispanic or Latino  Female  Anterior endometrium        Multifocal  2.7 4 or more
C3L-00771   S028    Tumor   Tumor   Other_specify   FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT3a (FIGO IIIA)    pN0 cM0 Staging Incomplete  Stage III   IIIA    1.0 22.86   86.0    No  White   Not-Hispanic or Latino  Female  Posterior endometrium       Multifocal  6.0 Unknown
C3L-00780   S029    Tumor   Tumor   Other_specify   FIGO grade 2    Not identified  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 No pathologic evidence of distant metastasis    Stage I IA  0.0 46.41   69.0    Yes White   Hispanic or Latino  Female  Other, specify  Posterior and Anterior Endometrium  Unifocal    1.7 2
C3L-00781   S030    Tumor   Tumor   Other_specify   FIGO grade 3    50 % or more    Endometrioid    YES Normal  pT2 (FIGO II)   pN0 cM0 No pathologic evidence of distant metastasis    Stage II    II  1.0 71.09   48.0    No  White   Hispanic or Latino  Female  Other, specify  Anterior and Posterior Endometrium  Unifocal    5.5 4 or more
C3L-00905   S031    Tumor   Tumor   United States   FIGO grade 3    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pN1 (FIGO IIIC1)    Staging Incomplete  No pathologic evidence of distant metastasis    Stage III   IIIC1   1.0 44.81   64.0    No  White   Not-Hispanic or Latino  Female  Other, specify  anterior and posterior  Unifocal    4.5 Unknown
C3L-00918   S032    Tumor   Tumor   Other_specify   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 No pathologic evidence of distant metastasis    Stage I IA  1.0 43.0    68.0    Yes White   Not-Hispanic or Latino  Female  Other, specify  Both anterior and posterior endometrium Unifocal    3.0 2
C3L-00921   S033    Tumor   Tumor   United States   FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT2 (FIGO II)   pN0 cM0 No pathologic evidence of distant metastasis    Stage II    II  1.0 32.32   66.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior  Unifocal    4.0 3
C3L-00932   S034    Tumor   Tumor   Other_specify   FIGO grade 2    Not identified  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 47.82   67.0    No  White   Not-Hispanic or Latino  Female  Other, specify  left cornu  Unifocal    1.0 3
C3L-00942   S036    Tumor   Tumor   Other_specify   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX Staging Incomplete  Staging Incomplete  Stage I IA  0.0 31.58   64.0    No  White   Not reported    Female  Anterior endometrium        Unifocal    4.5 None
C3L-00946   S037    Tumor   Tumor   Other_specify   FIGO grade 1    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pN0 Staging Incomplete  Staging Incomplete  Stage I IB  1.0 17.64   64.0    No  White   Not reported    Female  Posterior endometrium       Multifocal  3.9 1
C3L-00947   S038    Tumor   Tumor   Other_specify   FIGO grade 2    Not identified  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 36.84   71.0    Yes White   Not reported    Female  Posterior endometrium       Multifocal  1.8 2
C3L-00949   S039    Tumor   Tumor   Other_specify   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX Staging Incomplete  Staging Incomplete  Stage I IA  1.0 37.69   64.0    Yes White   Not reported    Female  Other, specify  along anterior and posterior surface    Unifocal    2.5 2
C3L-00961   S040    Tumor   Tumor   Other_specify   FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 28.5    59.0    No  White   Not reported    Female  Anterior endometrium        Multifocal  4.5 2
C3L-00963   S041    Tumor   Tumor   Other_specify       50 % or more    Serous  YES Normal  pT1b (FIGO IB)  pNX Staging Incomplete  Staging Incomplete  Stage I IB  1.0 34.89   59.0    Yes White   Not reported    Female  Other, specify  along anterior and posterior surface    Unifocal    2.6 1
C3L-01246   S042    Tumor   Tumor   Other_specify       under 50 %  Serous  YES Normal  pT1a (FIGO IA)  pN0 Staging Incomplete  Staging Incomplete  Stage I IA  0.0 39.14   62.0    No  White   Not reported    Female  Posterior endometrium       Unifocal    2.3 1
C3L-01248   S044    Tumor   Tumor   Other_specify   FIGO grade 1    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pNX Staging Incomplete  Staging Incomplete  Stage II    IB  0.0 59.78   42.0    No  White   Not reported    Female  Posterior endometrium       Unifocal    6.3 1
C3L-01249   S045    Tumor   Tumor   Other_specify   FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 Staging Incomplete  Staging Incomplete  Stage I IA  0.0 38.89   65.0    No  White   Not reported    Female  Other, specify  Tumor occupies 75% of endometrial surface   Unifocal    6.5 1
C3L-01252   S046    Tumor   Tumor   Other_specify   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX Staging Incomplete  Staging Incomplete  Stage I IA  0.0 38.41   76.0    Yes White   Not reported    Female  Posterior endometrium       Unifocal    0.9 4 or more
C3L-01256   S048    Tumor   Tumor   Other_specify   FIGO grade 1    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pN0 Staging Incomplete  Staging Incomplete  Stage I IB  0.0 34.37   75.0    Yes White   Not reported    Female  Anterior endometrium        Unifocal    4.3 4 or more
C3L-01257   S049    Tumor   Tumor   Other_specify   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 Staging Incomplete  Staging Incomplete  Stage I IA  0.0 17.11   71.0    No  White   Not reported    Female  Other, specify  Tumor involves 75% of endometrial cavity per diagnostic pathology report    Unifocal    8.0 2
C3L-01275   S050    Tumor   Tumor   Other_specify   FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pN0 Staging Incomplete  Staging Incomplete  Stage I IB  1.0 32.06   65.0    No  Not Reported    Not reported    Female  Other, specify  100 PERCENT OF ENDOMETRIAL SURFACE INVOLVED Unifocal    5.0 Unknown
C3L-01282   S051    Tumor   Tumor   United States   FIGO grade 3    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 No pathologic evidence of distant metastasis    Stage I IA  1.0 31.96   64.0    No  White   Not-Hispanic or Latino  Female  Anterior endometrium        Unifocal    3.0 Unknown
C3L-01304   S053    Tumor   Tumor   United States   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 No pathologic evidence of distant metastasis    Stage I IA  0.0 41.44   68.0    Yes White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior  Unifocal    3.7 3
C3L-01307   S054    Tumor   Tumor   United States   FIGO grade 3    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM1 pM1 Stage IV    IVB 1.0 31.63   74.0    Yes White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior  Unifocal    3.5 3
C3L-01311   S055    Tumor   Tumor   United States   FIGO grade 1    Not identified  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 No pathologic evidence of distant metastasis    Stage I IA  0.0 37.11   55.0    No  White   Not-Hispanic or Latino  Female  Anterior endometrium        Unifocal    3.0 None
C3L-01312   S056    Tumor   Tumor   United States   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX Staging Incomplete  No pathologic evidence of distant metastasis    Stage I IA  0.0 31.96   56.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Anterior and Posterior  Unifocal    4.0 1
C3L-01744   S057    Tumor   Tumor   Other_specify   FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX Staging Incomplete  Staging Incomplete  Stage I IA  0.0 46.45   62.0    No  White   Not reported    Female  Anterior endometrium        Unifocal    2.2 2
C3L-01925   S058    Tumor   Tumor   United States       50 % or more    Serous  YES Normal  pT3b (FIGO IIIB)    pN1 (FIGO IIIC1)    Staging Incomplete  pM1 Stage IV    IVB 1.0 27.66   65.0    No  White   Not-Hispanic or Latino  Female  Other, specify  Anterior and posterior endometrium  Unifocal    4.5 None
C3N-00151   S059    Tumor   Tumor   Ukraine FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pN0 cM0 No pathologic evidence of distant metastasis    Stage I IB  0.0 27.1    60.0    Unknown         Female  Other, specify  Entire uterine cavity   Unifocal        2
C3N-00200   S060    Tumor   Tumor   United States   FIGO grade 2    Not identified  Endometrioid    YES Normal  pT2 (FIGO II)   pN1 (FIGO IIIC1)    Staging Incomplete  Staging Incomplete  Stage III   IIIC1       46.85   72.0    Yes Black or African American   Not-Hispanic or Latino  Female  Other, specify  anterior and posterior endometrial cavity   Multifocal  9.0 4 or more
C3N-00321   S061    Tumor   Tumor   Ukraine FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 26.0    64.0    No          Female  Other, specify  Uterine cavity  Multifocal  1.5 2
C3N-00322   S062    Tumor   Tumor   Ukraine FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 31.0    70.0    No          Female  Other, specify  Entire Uterine Cavity   Multifocal  2.6 2
C3N-00323   S063    Tumor   Tumor   Ukraine FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 27.0    78.0    No          Female  Other, specify  Uterine cavity  Multifocal  4.0 Unknown
C3N-00324   S064    Tumor   Tumor   Ukraine FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT2 (FIGO II)   pN0 cM0 Staging Incomplete  Stage II    II  0.0 35.0    66.0    Yes         Female  Other, specify  Uterine cavity  Multifocal  2.3 Unknown
C3N-00326   S065    Tumor   Tumor   Ukraine FIGO grade 1    Not identified  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 35.0    45.0    No          Female  Other, specify  Uterine cavity  Multifocal  1.3 2
C3N-00328   S066    Tumor   Tumor   Ukraine FIGO grade 3    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pN0 cM0 Staging Incomplete  Stage I IB  0.0 31.22   62.0    No          Female  Other, specify  Uterine cavity  Multifocal  3.0 Unknown
C3N-00333   S067    Tumor   Tumor   Ukraine FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 31.0    65.0    No          Female  Other, specify  Entire Uterine Cavity   Multifocal  1.0 Unknown
C3N-00334   S068    Tumor   Tumor   Ukraine FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 32.83   68.0    No          Female  Other, specify  Uterine cavity  Multifocal  1.4 1
C3N-00335   S069    Tumor   Tumor   Ukraine FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 29.52   57.0    No          Female  Other, specify  Uterine cavity  Multifocal  2.5 None
C3N-00337   S070    Tumor   Tumor   Ukraine FIGO grade 3    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pNX cM0 Staging Incomplete  Stage I IB  0.0 29.07   67.0    No          Female  Other, specify  Entire Uterine Cavity   Multifocal  1.3 1
C3N-00339   S071    Tumor   Tumor   Ukraine     under 50 %  Serous  YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 21.83   45.0    No          Female  Other, specify  Uterine cavity  Multifocal  1.3 Unknown
C3N-00340   S072    Tumor   Tumor   Ukraine     under 50 %  Serous  YES Normal  pT3a (FIGO IIIA)    pN1 (FIGO IIIC1)    cM0 Staging Incomplete  Stage III   IIIC1   1.0 27.0    60.0    No          Female  Other, specify  Uterine cavity  Multifocal  3.5 2
C3N-00377   S073    Tumor   Tumor   Ukraine FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 34.0    64.0    Yes         Female  Other, specify  Uterine cavity  Multifocal  1.0 Unknown
C3N-00379   S074    Tumor   Tumor   Ukraine FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 36.81   41.0    No          Female  Other, specify  Entire uterine cavity.  Multifocal  2.5 1
C3N-00383   S075    Tumor   Tumor   Ukraine FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 46.0    61.0    No          Female  Other, specify  Uterine cavity  Unifocal    4.0 1
C3N-00386   S076    Tumor   Tumor   Ukraine FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 27.31   44.0    No          Female  Other, specify  Entire uterine cavity.  Multifocal  2.3 2
C3N-00388   S077    Tumor   Tumor   Ukraine FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 20.55   59.0    No          Female  Other, specify  Entire uterine cavity.  Multifocal  4.0 1
C3N-00389   S078    Tumor   Tumor   Ukraine FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pN0 cM0 Staging Incomplete  Stage I IB  0.0 17.85   62.0    No          Female  Other, specify  Entire uterine cavity   Multifocal  1.5 1
C3N-00729   S079    Tumor   Tumor   United States   FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pN0 Staging Incomplete  Staging Incomplete  Stage II    IB  0.0 29.62   86.0    No  White   Not-Hispanic or Latino  Female  Other, specify  both anterior and posterior Multifocal  4.0 4 or more
C3N-00734   S080    Tumor   Tumor   United States   FIGO grade 1    50 % or more    Endometrioid    YES Normal  pT3a (FIGO IIIA)    pN0 Staging Incomplete  Staging Incomplete  Stage III   IIIA    1.0 38.97   53.0    No  White   Not-Hispanic or Latino  Female  Anterior endometrium        Unifocal    4.0 None
C3N-00743   S081    Tumor   Tumor   United States   FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 No pathologic evidence of distant metastasis    Stage I IA  0.0 48.46   53.0    No  Black or African American   Not-Hispanic or Latino  Female  Other, specify  Involves fundus, anterior and posterior walls   Multifocal  3.5 2
C3N-00836   S082    Tumor   Tumor   Ukraine FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM1 Staging Incomplete  Stage I IA  0.0 30.47   75.0    No          Female  Other, specify  Entire uterine cavity   Multifocal  1.0 3
C3N-00847   S083    Tumor   Tumor   Ukraine FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT3a (FIGO IIIA)    pN0 cM0 Staging Incomplete  Stage III   IIIA    0.0 34.53   65.0    No          Female  Other, specify  Entire uterine cavity   Multifocal  4.3 2
C3N-00848   S084    Tumor   Tumor   Ukraine FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 33.65   66.0    Yes         Female  Other, specify  Entire uterine cavity   Multifocal  3.0 None
C3N-00850   S085    Tumor   Tumor   Ukraine FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 28.84   65.0    No          Female  Other, specify  Entire uterine cavity   Multifocal  1.0 1
C3N-00858   S086    Tumor   Tumor   Poland  FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT3b (FIGO IIIB)    pN0 cM0 No pathologic evidence of distant metastasis    Stage III   IIIB    1.0 36.0    65.0    No          Female  Anterior endometrium        Multifocal  11.0    2
C3N-00866   S087    Tumor   Tumor   United States   FIGO grade 1    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 No pathologic evidence of distant metastasis    Stage I IA  0.0 23.88   77.0    Yes White   Not-Hispanic or Latino  Female  Other, specify  Anterior, posterior and fundus  Multifocal  3.0 4 or more
C3N-00880   S088    Tumor   Tumor   Poland  FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pN0 cM0 No pathologic evidence of distant metastasis    Stage I IA  0.0 27.0    61.0    No          Female  Anterior endometrium        Unifocal    3.2 1
C3N-01003   S090    Tumor   Tumor   Poland  FIGO grade 1    50 % or more    Endometrioid    YES Normal  pT3b (FIGO IIIB)    pN0 cM1 pM1 Stage IV    IVB 0.0 31.0    73.0    Yes         Female  Anterior endometrium        Multifocal  3.0 4 or more
C3N-01211   S091    Tumor   Tumor   Ukraine FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT2 (FIGO II)   pN0 cM0 Staging Incomplete  Stage II    II  1.0 39.2    59.0    No          Female  Other, specify  Entire uterine cavity   Multifocal  1.4 1
C3N-01212   S092    Tumor   Tumor   Ukraine FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT3a (FIGO IIIA)    pNX cM0 Staging Incomplete  Stage III   IIIA    1.0 30.48   63.0    No          Female  Other, specify  Entire uterine cavity   Unifocal    1.5 2
C3N-01217   S093    Tumor   Tumor   Ukraine FIGO grade 1    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pNX cM0 Staging Incomplete  Stage I IB  0.0 36.2    58.0    No          Female  Other, specify  Endometrium Multifocal  0.8 None
C3N-01219   S094    Tumor   Tumor   Ukraine FIGO grade 3    under 50 %  Endometrioid    YES Normal  pT3a (FIGO IIIA)    pN0 cM0 Staging Incomplete  Stage III   IIIA    0.0 26.14   58.0    No          Female  Other, specify  Entire uterine cavity   Unifocal    5.0 1
C3N-01267   S095    Tumor   Tumor   Ukraine FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT1b (FIGO IB)  pN1 (FIGO IIIC1)    cM0 Staging Incomplete  Stage III   IIIC1   1.0 30.85   57.0    No          Female  Other, specify  Entire uterine cavity   Multifocal  1.2 2
C3N-01346   S096    Tumor   Tumor   Poland      50 % or more    Serous  YES Normal  pT1b (FIGO IB)  pN2 (FIGO IIIC2)    cM0 No pathologic evidence of distant metastasis    Stage III   IIIC2   1.0 34.0    63.0                Female  Anterior endometrium        Unifocal    5.5 1
C3N-01349   S097    Tumor   Tumor   Poland      50 % or more    Serous  YES Normal  pT1b (FIGO IB)  pN0 cM0 No pathologic evidence of distant metastasis    Stage I IB  1.0 31.0    77.0    Yes         Female  Anterior endometrium        Multifocal  5.0 4 or more
C3N-01510   S098    Tumor   Tumor   United States   FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT2 (FIGO II)   pNX Staging Incomplete  Staging Incomplete  Stage II    II  1.0 40.72   53.0    Yes White   Not-Hispanic or Latino  Female  Other, specify  Bulky tumor involving both anterior and posterior walls Multifocal  8.5 None
C3N-01520   S099    Tumor   Tumor   Ukraine FIGO grade 2    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 29.37   69.0    No          Female  Other, specify  Endometrium Multifocal  1.0 2
C3N-01521   S100    Tumor   Tumor   Ukraine FIGO grade 3    under 50 %  Endometrioid    YES Normal  pT1a (FIGO IA)  pNX cM0 Staging Incomplete  Stage I IA  0.0 29.4    75.0    No          Female  Other, specify  Entire uterine cavity   Unifocal    4.2 2
C3N-01537   S101    Tumor   Tumor   Ukraine FIGO grade 2    50 % or more    Endometrioid    YES Normal  pT2 (FIGO II)   pN0 cM0 Staging Incomplete  Stage II    II  0.0 35.42   74.0    No          Female  Other, specify  Entire uterine cavity   Unifocal    1.5 1
C3N-01802   S102    Tumor   Tumor   United States       under 50 %  Serous  YES Normal  pT2 (FIGO II)   pN0 Staging Incomplete  Staging Incomplete  Stage II    II  1.0 24.32   85.0    Yes Black or African American   Not-Hispanic or Latino  Female  Other, specify  entire uterine cavity   Unifocal    3.8 1
C3N-01825   S103    Tumor   Tumor   Ukraine     under 50 %  Serous  YES Normal  pT1a (FIGO IA)  pN0 cM0 Staging Incomplete  Stage I IA  0.0 34.06   70.0    No          Female  Other, specify  Entire uterine cavity   Unifocal    5.0 Unknown
C3L-00006.N S105    Normal  Adjacent_normal                                                                                             
C3L-00361.N S106    Normal  Adjacent_normal                                                                                             
C3L-00563.N S130    Normal  Myometrium_normal                                                                                               
C3L-00586.N S107    Normal  Adjacent_normal                                                                                             
C3L-00601.N S108    Normal  Adjacent_normal                                                                                             
C3L-00605.N S131    Normal  Myometrium_normal                                                                                               
C3L-00769.N S109    Normal  Adjacent_normal                                                                                             
C3L-00770.N S132    Normal  Myometrium_normal                                                                                               
C3L-00771.N S133    Normal  Myometrium_normal                                                                                               
C3L-00930.N S110    Normal  Adjacent_normal                                                                                             
C3L-00932.N S111    Normal  Adjacent_normal                                                                                             
C3L-00947.N S112    Normal  Adjacent_normal                                                                                             
C3L-00963.N S113    Normal  Adjacent_normal                                                                                             
C3L-01246.N S114    Normal  Adjacent_normal                                                                                             
C3L-01249.N S115    Normal  Adjacent_normal                                                                                             
C3L-01252.N S116    Normal  Adjacent_normal                                                                                             
C3L-01256.N S117    Normal  Adjacent_normal                                                                                             
C3L-01257.N S118    Normal  Adjacent_normal                                                                                             
C3L-01282.N S119    Normal  Adjacent_normal                                                                                             
C3L-01304.N S120    Normal  Adjacent_normal                                                                                             
C3L-01307.N S121    Normal  Adjacent_normal                                                                                             
C3L-01311.N S122    Normal  Adjacent_normal                                                                                             
C3L-01744.N S123    Normal  Adjacent_normal                                                                                             
C3N-00200.N S134    Normal  Myometrium_normal                                                                                               
C3N-00333.N S124    Normal  Adjacent_normal                                                                                             
C3N-00383.N S125    Normal  Adjacent_normal                                                                                             
C3N-00729.N S126    Normal  Adjacent_normal                                                                                             
C3N-00858.N S127    Normal  Adjacent_normal                                                                                             
C3N-00866.N S128    Normal  Adjacent_normal                                                                                             
C3N-01211.N S135    Normal  Myometrium_normal                                                                                               
C3N-01346.N S129    Normal  Adjacent_normal                                                                                             
NX1.N   S136    Normal  Enriched_normal                                                                                             
NX10.N  S145    Normal  Enriched_normal                                                                                             
NX11.N  S146    Normal  Enriched_normal                                                                                             
NX12.N  S147    Normal  Enriched_normal                                                                                             
NX13.N  S148    Normal  Enriched_normal                                                                                             
NX14.N  S149    Normal  Enriched_normal                                                                                             
NX15.N  S150    Normal  Enriched_normal                                                                                             
NX16.N  S151    Normal  Enriched_normal                                                                                             
NX17.N  S152    Normal  Enriched_normal                                                                                             
NX18.N  S153    Normal  Enriched_normal                                                                                             
NX2.N   S137    Normal  Enriched_normal                                                                                             
NX3.N   S138    Normal  Enriched_normal                                                                                             
NX4.N   S139    Normal  Enriched_normal                                                                                             
NX5.N   S140    Normal  Enriched_normal                                                                                             
NX6.N   S141    Normal  Enriched_normal                                                                                             
NX7.N   S142    Normal  Enriched_normal                                                                                             
NX8.N   S143    Normal  Enriched_normal                                                                                             
NX9.N   S144    Normal  Enriched_normal

Here is my code:

import pandas as pd
import sys
d = {}

file = sys.argv[1]

df = pd.read_csv(file, sep="\t", header = 0, index_col = 0)
stages = df.iloc[:,14]
for x in stages:
    if not pd.isnull(x): 
        if x in d:
            d[x] = d[x]   1
        else:
            d[x] = 1
d = dict(sorted(d.items(), key=lambda item: item[1]))
for x in reversed(list(d.keys())):
    print(f"{x}\t{d[x]}")
print("Name: FIGO_stage, dtype: int64")

Which outputs this:

IA  56
IB  15
II  8
IIIA    6
IIIC1   4
IVB 3
IIIC2   2
IIIB    1

I need it formatted according to pandas dataframe format, like this:

IA       56
IB       15
II        8
IIIA      6
IIIC1     4
IVB       3
IIIC2     2
IIIB      1
Name: FIGO_stage, dtype: int64

How would one do this using built-in pandas functionality?

CodePudding user response:

IIUC, use value_counts:

df = pd.read_table(file)
count = df['FIGO_stage'].value_counts()
print(count)

# Output
IA       56
IB       15
II        8
IIIA      6
IIIC1     4
IVB       3
IIIC2     2
IIIB      1
Name: FIGO_stage, dtype: int64
  • Related