python 如何把小数变成百分数格式
生活随笔
收集整理的這篇文章主要介紹了
python 如何把小数变成百分数格式
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1. 數(shù)據(jù)樣本
,valid_rate,homework_rate,inter_rate,playback_rate,zhujiang_good_comment5_rate,fudao_good_comment5_rate,if_purchased,cust,cust_per 0,0.629536534447,0.216511482255,0.70731691023,-8.04911692853e-16,0.948508768267,0.982603131524,0.0751565762004,479,0.188582677165 1,0.858778725237,0.93392997416,0.925245478036,2.16493489802e-15,0.953323341947,0.984113953488,0.118863049096,1161,0.457086614173 2,0.827973648649,0.732318581081,0.883406081081,0.0844594594595,0.332026351351,0.0472962837838,0.0777027027027,296,0.116535433071 3,0.728237267081,0.823232608696,0.788694409938,1.0,0.938818944099,0.922187888199,0.111801242236,322,0.126771653543 4,0.260557092199,0.157164539007,0.329861347518,0.063829787234,0.436144680851,0.00709219858156,0.0567375886525,282,0.1110236220472. format 把cust_per打印成百分值輸出
iloc取指定位置的元素
r = pd.read_csv(r_file, header=0) # print r['cust_per'].head(1) # 不行,會(huì)同時(shí)輸出列名或者序號(hào) print format(r.iloc[0,-1], '.0%') # iloc取第0行最后1列位置的元素3. 把打印出來的百分值拼接起來
''' 遇到問題沒人解答?小編創(chuàng)建了一個(gè)Python學(xué)習(xí)交流QQ群:531509025 尋找有志同道合的小伙伴,互幫互助,群里還有不錯(cuò)的視頻學(xué)習(xí)教程和PDF電子書! ''' fig = plt.figure()ax = fig.add_subplot(111, polar=True)# polar參數(shù)!!ax.plot(angles, data0, 'bo-', linewidth=1,label=u'1類%.2f%%' % (r.iloc[0,-1]*100) )# 畫線ax.plot(angles, data1, 'go-', linewidth=1,label=u'2類%.2f%%' % (r.iloc[1,-1]*100))# 畫線ax.plot(angles, data2, 'co-', linewidth=1,label=u'3類%.2f%%' % (r.iloc[2,-1]*100))# 畫線ax.plot(angles, data3, 'ro-', linewidth=1,label=u'4類%.2f%%' % (r.iloc[3,-1]*100))# 畫線ax.plot(angles, data4, 'mo-', linewidth=1,label=u'5類%.2f%%' % (r.iloc[4,-1]*100))# 畫線4. 調(diào)整圖例和圖的位置
#利用bbox_to_anchor 來調(diào)整圖例 box = ax.get_position() ax.set_position([box.x0, box.y0, box.width*0.8, box.height]) ax.legend(loc='upper right', bbox_to_anchor=(0.2, 1.12),ncol=1)5. 保存 matlibplot.plot 畫出來的圖
plt.savefig('D:/a/b.png') 與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的python 如何把小数变成百分数格式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python中用dict统计列表中元素出
- 下一篇: Python中map和reduce函数?