Pandas.DataFrame rows required percentage (logarithmic scale)

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/a19990412/article/details/90745056

Brief

Motivation

  • In general, the number of content of each portion is more readily available, but the proportion (percent) of such secondary data is data, such operation is very common
  • The process of internal change information ratio compared to the sheer numbers but also reflects the overall system of migration

Contribution

  • For example, there is no problem of follow -

Codes

  • Importing part of the package, I do not write Kazakhstan

It is assumed that each row is the data that belongs to a different month

>>> df
         a   b   c   d   e
month0   0   1   2   3   4
month1   5   6   7   8   9
month2  10  11  12  13  14
month3  15  16  17  18  19
  • Percentage change
    • Columns (i.e. columns projected to) summation
    • Row (i.e. line projected) division
>>> df.div(df.sum(axis=1), axis=0)
               a         b    c         d         e
month0  0.000000  0.100000  0.2  0.300000  0.400000
month1  0.142857  0.171429  0.2  0.228571  0.257143
month2  0.166667  0.183333  0.2  0.216667  0.233333
month3  0.176471  0.188235  0.2  0.211765  0.223529

Guess you like

Origin blog.csdn.net/a19990412/article/details/90745056