我有計算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
分鐘-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 \ count 978.000000 978.000000
平均值0.036843 0.002883
std 2.471833 2.576255
分鐘-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
標準2.012941 2.671352
分鐘-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
分鐘-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
std ... 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
分鐘-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
分鐘-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
STD 2.616890 2.135260
分鐘-31.187200 -15.955000
25%-0.608050 -0.732750
50%0.008050 -0.116500
75%0.638025 0.647625
max 23.3481 00 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
分鐘-23.168000 -27.271400
25%-0.674500 -0.683150
50%-0.026800 - 0.001000
75%0.711800 0.721400
max 38.533300 27。568000
CID CXA061_SKL_48H_X1_B29:P24
計978.000000
意味着-0.043314
STD 1.704406
分鐘-9.464100
25%-0.780525
50%-0.144250
75%0.515325
最大19.056400
[8 rows x 372 columns]
用退出代碼0結束的過程
嘗試變換的值浮動!!老實說,雖然有更多的背景知道你如何計算這些中位數是必需的。如果data_df是熊貓數據框,請告訴我們 –
@GauravDhama是的,data_df是一個熊貓數據框。順便說一下,這將工作:gene_medians = GCT_object.data_df.median(axis = 1) unrounded_gm = format(gene_medians,「.7f」) – user8669
你可以發佈一個詳細的代碼,因爲這不是熊貓數據框中的常見行爲。我不認爲你在問題中提到的特定代碼行是問題所在。 –