資料視覺效果 -- Python

來源:互聯網
上載者:User

標籤:text   準備   int   ceshi   ima   mongod   結果   log   資料庫操作   

前提條件:

熟悉認知新的編程工具(jupyter notebook)

1、安裝:採用pip的方式來安裝Jupyter。輸入安裝命令pip install jupyter即可;

2、啟動:安裝完成後,我們可在如下目錄找到jupyter-notebook這個應用;雙擊啟動

如所示:

 

3、開啟瀏覽器編譯器

至此編程工具準備完畢。

 

資料視覺效果實戰教程:
import pymongoimport charts
client = pymongo.MongoClient(‘localhost‘,27017)ceshi = client[‘ceshi‘]item_info = ceshi[‘item_info‘]
for i in item_info.find().limit(300):    if i[‘area‘] == [‘‘]:        pass    else:        print(i[‘area‘])
area_list = []for i in item_info.find().limit(300):    if i[‘area‘] == [‘‘]:        pass    else:        area_list.append(i[‘area‘][1])area_index = list(set(area_list))print(area_index)
post_times = []for index in area_index:    post_times.append(area_list.count(index))print(post_times)    
data_gen(‘column‘)
def data_gen(types):    length = 0    if length <= len(area_index):        for area,times in zip(area_index,post_times):            data = {                ‘name‘:area,                ‘data‘:[times],                ‘type‘:types            }            yield data            length += 1    

 

for i in data_gen(‘column‘):    print(i)
series = [data for data in data_gen(‘column‘)]charts.plot(series,show=‘inline‘,options=dict(title=dict(text=‘杭州發帖資料統計-WangWang‘)))

 

最終運行結果:

 

 總結知識點:

1、charts模組的引入及使用;

2、列表中append()函數使用;

3、count()函數使用;

4、集合函數set()的使用;

5、列表解析式的使用;

6、zip()函數的使用;

7、yield產生器的使用;

8、MongoDb資料庫操作使用;

 

資料視覺效果 -- Python

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.