如何防止我的中位数被舍入?

时间:2016-08-03 15:33:22

标签: python rounding median

我有代码计算z分数的中位数,范围从0到1.Python将所有这些数字四舍五入为0.我如何确保这些数字不是舍入的?

这是我计算中位数的代码行:

gene_medians = GCT_object.data_df.median(axis=1)
import matplotlib.pyplot as plt
import parse_gctoo

def histo_plotter(file, plot_title, ax):
    # read in file as string
    GCT_object = parse_gctoo.parse(file)
    # computing median of rows in data_df
    gene_medians = GCT_object.data_df.median(axis=1)
    unrounded_gm = format(gene_medians, ".7f")
    # making histogram of medians
    print gene_medians'

.describe的结果: /Users/eibelman/miniconda2/envs/josh_env/bin/python2.7/Users/eibelman/Analysis/ComparingMedianGeneExpressionDifCellLines.py cid CXA061_SKL_48H_X1_B29:A03 CXA061_SKL_48H_X1_B29:A04 \ 数978.000000 978.000000
平均值0.072729 0.078196
std 2.909874 3.086884
min -18.698500 -63.467600
25%-0.742375 -0.422625
50%-0.030950 0.205600
75%0.656550 0.885275
最高29.803200 27.347300

cid CXA061_SKL_48H_X1_B29:A05 CXA061_SKL_48H_X1_B29:A06 \ 数978.000000 978.000000
平均值0.036843 0.002883
std 2.471833 2.576255
min -17.170500 -26.433600
25%-0.653925 -0.674250
50%-0.081250 -0.070600
75%0.548900 0.561250
最大31.356600 34.249100

cid CXA061_SKL_48H_X1_B29:A07 CXA061_SKL_48H_X1_B29:A08 \ 数978.000000 978.000000
平均值0.017625 0.096359
std 2.012941 2.671352
min -18.651800 -27.609600
25%-0.711400 -0.730225
50%-0.048900 -0.012100
75%0.585300 0.670100
最高23.690800 27.509200

cid CXA061_SKL_48H_X1_B29:A09 CXA061_SKL_48H_X1_B29:A10 \ 数978.000000 978.000000
平均值-0.024301 -0.048213
std 3.317470 3.431853
min -70.184100 -43.255000
25%-0.556725 -0.916150
50%0.009950 -0.071200
75%0.629525 0.836525
最大32.083000 36.831200

cid CXA061_SKL_48H_X1_B29:A11 CXA061_SKL_48H_X1_B29:A12 \ 数978.000000 978.000000
平均值0.040646 -0.013686
std 2.568421 3.296173
min -17.213400 -42.862500
25%-0.636600 -0.719425
50%-0.032850 -0.033950
75%0.593925 0.680675
最高26.524500 50.334500

cid ...... CXA061_SKL_48H_X1_B29:P15 \ 伯爵... 978.000000
意思是...... -0.006012
标准... 2.564106
min ... -20.208400
25%...... -0.706475
50%...... -0.136300
75%...... 0.557025
最大... 27.509500

cid CXA061_SKL_48H_X1_B29:P16 CXA061_SKL_48H_X1_B29:P17 \ 数978.000000 978.000000
平均值0.041587 -0.001685
std 1.713974 3.091669
min -12.695900 -34.948900
25%-0.569150 -0.642050
50%0.000000 0.050800
75%0.637700 0.818025
最高22.556600 25.772400

cid CXA061_SKL_48H_X1_B29:P18 CXA061_SKL_48H_X1_B29:P19 \ 数978.000000 978.000000
平均值-0.019696 0.061637
std 2.570132 2.648487
min -33.142900 -29.076300
25%-0.798700 -0.632600
50%-0.057600 0.048900
75%0.588375 0.679500
最高30.018900 30.709400

cid CXA061_SKL_48H_X1_B29:P20 CXA061_SKL_48H_X1_B29:P21 \ 数978.000000 978.000000
平均值0.026416 -0.004739
标准2.616890 2.135260
min -31.187200 -15.955000
25%-0.608050 -0.732750
50%0.008050 -0.116500
75%0.638025 0.647625
最高23.348100 24.229200

cid CXA061_SKL_48H_X1_B29:P22 CXA061_SKL_48H_X1_B29:P23 \ 数978.000000 978.000000
平均值0.019632 0.002053
std 2.581926 2.356626
min -23.168000 -27.271400
25%-0.674500 -0.683150
50%-0.026800 -0.001000
75%0.711800 0.721400
最大值38.533300 27.568000

cid CXA061_SKL_48H_X1_B29:P24
数978.000000
平均值-0.043314
std 1.704406
min -9.464100
25%-0.780525
50%-0.144250
75%0.515325
最高19.056400

[8行x 372列]

处理完成,退出代码为0

1 个答案:

答案 0 :(得分:0)

如果您正在使用pandas数据框(data_df),那么您可以使用numpy包的中值函数。

gene_medians = numpy.median(GCT_object.data_df[[1]])

gene_medians = GCT_object.data_df[[1]].apply(numpy.median)