日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

【Web开发】Python实现Web图表功能(D-Tale入门)

發(fā)布時(shí)間:2023/12/16 python 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Web开发】Python实现Web图表功能(D-Tale入门) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

🍺基于Flask實(shí)現(xiàn)服務(wù)器的相關(guān)文章如下🍺:

  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web服務(wù)器(Flask快速入門(mén))🎈
  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web服務(wù)器(Flask案例測(cè)試)🎈
  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web服務(wù)器(Flask部署上線(xiàn))🎈
  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web服務(wù)器(Flask+Tornado+nginx)🎈
  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web服務(wù)器(Ubuntu下安裝Flask)🎈
  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web服務(wù)器(Ubuntu下打包Flask)🎈
  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web服務(wù)器(Ubuntu下調(diào)試Flask)🎈
  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web服務(wù)器(Ubuntu下Flask使用MySQL)🎈
  • 🍺基于Python實(shí)現(xiàn)Web圖表功能的相關(guān)文章如下🍺:

  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web圖表功能(D-Tale入門(mén))🎈
  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web圖表功能(D-Tale編譯)🎈
  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web圖表功能(pyecharts,Flask)🎈
  • 🎈【W(wǎng)eb開(kāi)發(fā)】Python實(shí)現(xiàn)Web圖表功能(Grafana)🎈
  • 文章目錄

    • 1、D-Tale
      • 1.1 D-Tale簡(jiǎn)介
      • 1.2 D-Tale安裝
      • 1.3 D-Tale測(cè)試
    • 2、ngrok代理
      • 2.1 簡(jiǎn)介
      • 2.2 安裝
      • 2.3 測(cè)試
    • 3、Python線(xiàn)程
      • 3.1 _thread模塊
      • 3.2 threading模塊
    • 結(jié)語(yǔ)

    1、D-Tale

    1.1 D-Tale簡(jiǎn)介

    D-Tale 是 Fl??ask 后端和 React 前端的組合,為您提供查看和分析 Pandas 數(shù)據(jù)結(jié)構(gòu)的簡(jiǎn)單方法。它與 ipython 筆記本和 python/ipython 終端無(wú)縫集成。目前該工具支持 DataFrame、Series、MultiIndex、DatetimeIndex 和 RangeIndex 等 Pandas 對(duì)象。

    D-Tale 是 SAS 到 Python 轉(zhuǎn)換的產(chǎn)物。最初是基于 SAS功能 insight 的 perl 腳本包裝器,現(xiàn)在是基于 Pandas 數(shù)據(jù)結(jié)構(gòu)的輕量級(jí) Web 客戶(hù)端。

    1.2 D-Tale安裝

    pip install dtale


    or

    # conda conda install dtale -c conda-forge # if you want to also use "Export to PNG" for charts conda install -c plotly python-kaleido

    1.3 D-Tale測(cè)試

    D-Tale支持多種文件格式,包括CSV、TSV、XLS、XLSX。它是一個(gè)以Flask 為后端,React 作為前端構(gòu)建的,通過(guò)pip安裝即可。數(shù)據(jù)的導(dǎo)入主要有如下幾種方式:
    (1)從文件加載數(shù)據(jù)
    (2)從網(wǎng)站加載數(shù)據(jù)。需要傳遞網(wǎng)站的鏈接,可以從中獲取 CSV、JSON、TSV 或 Excel 等文件。
    (3)加載示例數(shù)據(jù)集。這些數(shù)據(jù)集可能需要一些后臺(tái)下載才能從服務(wù)器獲取數(shù)據(jù)集。

    • (1)入門(mén)例子
    import dtale dtale.show(open_browser=True)

    測(cè)試結(jié)果如下:

    • (2)顯示數(shù)組
    import dtale import pandas as pd df = pd.DataFrame([dict(a=1,b=2,c=3), dict(a=123.732,b=1.414,c=3.1415)]) dtale.show(df, open_browser=True)

    • (3)展示excel文件
    import dtale import pandas as pd df = pd.read_csv('d:/iris.csv') dtale.show(df, open_browser=True) import dtale import pandas as pddf = pd.read_csv("/data/test.csv", sep=";") dtale.show(df, vertical_headers=False)

    • (4)顯示網(wǎng)絡(luò)數(shù)據(jù)
    import dtale import seaborn as snsdf=sns.load_dataset('planets') dtale.show(df, ignore_duplicate=True, open_browser=True)

    • (5)復(fù)雜例子
    import dtale import pandas as pddf = pd.DataFrame([dict(a=1,b=2,c=3)])# Assigning a reference to a running D-Tale process d = dtale.show(df)# Accessing data associated with D-Tale process tmp = d.data.copy() tmp['d'] = 4# Altering data associated with D-Tale process # FYI: this will clear any front-end settings you have at the time for this process (filter, sorts, formatting) d.data = tmp# Shutting down D-Tale process d.kill()# using Python's `webbrowser` package it will try and open your server's default browser to this process d.open_browser()# There is also some helpful metadata about the process d._data_id # the process's data identifier d._url # the url to access the processd2 = dtale.get_instance(d._data_id) # returns a new reference to the instance running at that data_iddtale.instances() # prints a list of all ids & urls of running D-Tale sessions

    2、ngrok代理

    2.1 簡(jiǎn)介

    ngrok會(huì)在您計(jì)算機(jī)上的本地Web服務(wù)器上創(chuàng)建安全的公共URL(https://yourapp.ngrok.io)。快速迭代,立即反饋,不中斷流量。


    2.2 安裝

    • (1)下載ngrok
      https://ngrok.com/download

    • (2)安裝您的Authtoken:
      ngrok.com服務(wù)的許多高級(jí)功能在后面的章節(jié)中描述要求您注冊(cè)一個(gè)帳戶(hù)。 注冊(cè)后,您需要使用顯示在信息中心上的authtoken配置ngrok。 這將授予您訪問(wèn)僅限帳戶(hù)功能的權(quán)限。 ngrok有一個(gè)簡(jiǎn)單的“authtoken”命令,使這很容易。 在引擎蓋下,所有的authtoken命令是添加(或修改)authtoken屬性在您的ngrok配置文件。

    ngrok authtoken <YOUR_AUTHTOKEN>

    2.3 測(cè)試

    • (1)將本地計(jì)算機(jī)的端口80上的Web服務(wù)器公開(kāi)到互聯(lián)網(wǎng):
    ngrok http 8080

    • (2)ngrok提供了一個(gè)實(shí)時(shí)的Web UI,您可以在其中內(nèi)省您的隧道上運(yùn)行的所有HTTP流量。在啟動(dòng)ngrok之后,只需在Web瀏覽器中打開(kāi)http://localhost:4040即可檢查請(qǐng)求詳細(xì)信息。
    http://localhost:4040/

    http://localhost:8080/cars


    3、Python線(xiàn)程

    3.1 _thread模塊

    _thread實(shí)現(xiàn)多線(xiàn)程主要通過(guò):
    _thread.start_new(執(zhí)行的方法的名稱(chēng),當(dāng)前執(zhí)行方法需要的參數(shù))

    #!/usr/bin/env python3 # -*- coding: utf-8 -*-import _thread import timedef print_time(thread_name, delay):count = 0while count < 5:time.sleep(delay)count += 1print("線(xiàn)程名:{0},當(dāng)前的時(shí)間為:{1}".format(thread_name,time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))# 創(chuàng)建兩個(gè)線(xiàn)程 try:_thread.start_new_thread(print_time, ("Thread-1", 2))_thread.start_new_thread(print_time, ("Thread-2", 4)) except:print("Error :線(xiàn)程無(wú)法啟動(dòng)線(xiàn)程")while 1:pass


    _thread加鎖:

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- import _thread from time import sleep, ctimeloop_times = [4, 2]def loop_func(nloop, nsec, lock):print("start loop: {0}, at:{1}".format(nloop, ctime()))sleep(nsec)print("end loop: {0}, at :{1}".format(nloop, ctime()))lock.release() # 這里是釋放鎖def main():print("starting at:{0}".format(ctime()))loop_locks = []nloops = range(len(loop_times))for i in nloops:lock = _thread.allocate_lock() # 獲得線(xiàn)程的本地鎖lock.acquire() # 開(kāi)始加鎖,獲得鎖并加鎖loop_locks.append(lock) # 項(xiàng)當(dāng)前的鎖集合中添加該鎖for i in nloops:_thread.start_new(loop_func,(i, loop_times[i], loop_locks[i])) # 反復(fù)檢查鎖是否被鎖住,如果被鎖住就一直死循環(huán),否者停止循環(huán)檢查for i in nloops:while loop_locks[i].locked(): pass print("all DONE at:{0}".format(ctime()))if __name__ == "__main__":main()

    3.2 threading模塊

    更高級(jí)的threading模塊。
    通過(guò)threading.Thread(執(zhí)行的函數(shù),name=“執(zhí)行線(xiàn)程的名稱(chēng)”,args=(執(zhí)行函數(shù)需要的參數(shù)))創(chuàng)建一個(gè)可執(zhí)行的線(xiàn)程。

    #!/usr/bin/env python3 # -*- coding: utf-8 -*-import threading import timeclass Sum:count = 0#thread_lock = threading.Lock()def loop_func():while Sum.count < 10:time.sleep(1)#Sum.thread_lock.acquire() # 使用鎖的方式實(shí)現(xiàn)線(xiàn)程安全以及同步Sum.count += 1current_name = threading.currentThread().getName()current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) print("{0}:當(dāng)前執(zhí)行操作的時(shí)間:{1},當(dāng)前count的結(jié)果為:{2}".format(current_name, current_time, Sum.count))#Sum.thread_lock.release() # 釋放鎖def main():threading.Thread(target=loop_func, name="線(xiàn)程一").start()threading.Thread(target=loop_func, name="線(xiàn)程二").start()threading.Thread(target=loop_func, name="線(xiàn)程三").start()if __name__ == '__main__':main()

    結(jié)語(yǔ)

    如果您覺(jué)得該方法或代碼有一點(diǎn)點(diǎn)用處,可以給作者點(diǎn)個(gè)贊,或打賞杯咖啡;╮( ̄▽ ̄)╭
    如果您感覺(jué)方法或代碼不咋地//(ㄒoㄒ)//,就在評(píng)論處留言,作者繼續(xù)改進(jìn);o_O???
    如果您需要相關(guān)功能的代碼定制化開(kāi)發(fā),可以留言私信作者;(????)
    感謝各位大佬童鞋們的支持!( ′ ▽′ )ノ ( ′ ▽′)っ!!!

    總結(jié)

    以上是生活随笔為你收集整理的【Web开发】Python实现Web图表功能(D-Tale入门)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。