生活随笔
收集整理的這篇文章主要介紹了
【Web开发】Python实现Web图表功能(D-Tale入门)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
🍺基于Flask實現服務器的相關文章如下🍺:
🎈【Web開發】Python實現Web服務器(Flask快速入門)🎈 🎈【Web開發】Python實現Web服務器(Flask案例測試)🎈 🎈【Web開發】Python實現Web服務器(Flask部署上線)🎈 🎈【Web開發】Python實現Web服務器(Flask+Tornado+nginx)🎈 🎈【Web開發】Python實現Web服務器(Ubuntu下安裝Flask)🎈 🎈【Web開發】Python實現Web服務器(Ubuntu下打包Flask)🎈 🎈【Web開發】Python實現Web服務器(Ubuntu下調試Flask)🎈 🎈【Web開發】Python實現Web服務器(Ubuntu下Flask使用MySQL)🎈
🍺基于Python實現Web圖表功能的相關文章如下🍺:
🎈【Web開發】Python實現Web圖表功能(D-Tale入門)🎈 🎈【Web開發】Python實現Web圖表功能(D-Tale編譯)🎈 🎈【Web開發】Python實現Web圖表功能(pyecharts,Flask)🎈 🎈【Web開發】Python實現Web圖表功能(Grafana)🎈
文章目錄 1、D-Tale 1.1 D-Tale簡介 1.2 D-Tale安裝 1.3 D-Tale測試 2、ngrok代理 3、Python線程 3.1 _thread模塊 3.2 threading模塊 結語
1、D-Tale
1.1 D-Tale簡介
D-Tale 是 Fl??ask 后端和 React 前端的組合,為您提供查看和分析 Pandas 數據結構的簡單方法。它與 ipython 筆記本和 python/ipython 終端無縫集成。目前該工具支持 DataFrame、Series、MultiIndex、DatetimeIndex 和 RangeIndex 等 Pandas 對象。 D-Tale 是 SAS 到 Python 轉換的產物。最初是基于 SAS功能 insight 的 perl 腳本包裝器,現在是基于 Pandas 數據結構的輕量級 Web 客戶端。
1.2 D-Tale安裝
pip
install dtale
or
conda
install dtale
-c conda-forge
conda
install -c plotly python-kaleido
1.3 D-Tale測試
D-Tale支持多種文件格式,包括CSV、TSV、XLS、XLSX。它是一個以Flask 為后端,React 作為前端構建的,通過pip安裝即可。數據的導入主要有如下幾種方式: (1)從文件加載數據 (2)從網站加載數據。需要傳遞網站的鏈接,可以從中獲取 CSV、JSON、TSV 或 Excel 等文件。 (3)加載示例數據集。這些數據集可能需要一些后臺下載才能從服務器獲取數據集。
import dtale
dtale
. show
( open_browser
= True )
測試結果如下:
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 )
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 )
import dtale
import seaborn
as snsdf
= sns
. load_dataset
( 'planets' )
dtale
. show
( df
, ignore_duplicate
= True , open_browser
= True )
import dtale
import pandas
as pddf
= pd
. DataFrame
( [ dict ( a
= 1 , b
= 2 , c
= 3 ) ] )
d
= dtale
. show
( df
)
tmp
= d
. data
. copy
( )
tmp
[ 'd' ] = 4
d
. data
= tmp
d
. kill
( )
d
. open_browser
( )
d
. _data_id
d
. _url d2
= dtale
. get_instance
( d
. _data_id
) dtale
. instances
( )
2、ngrok代理
2.1 簡介
ngrok會在您計算機上的本地Web服務器上創建安全的公共URL(https://yourapp.ngrok.io)。快速迭代,立即反饋,不中斷流量。
2.2 安裝
(1)下載ngrok https://ngrok.com/download
(2)安裝您的Authtoken: ngrok.com服務的許多高級功能在后面的章節中描述要求您注冊一個帳戶。 注冊后,您需要使用顯示在信息中心上的authtoken配置ngrok。 這將授予您訪問僅限帳戶功能的權限。 ngrok有一個簡單的“authtoken”命令,使這很容易。 在引擎蓋下,所有的authtoken命令是添加(或修改)authtoken屬性在您的ngrok配置文件。
ngrok authtoken
< YOUR_AUTHTOKEN
>
2.3 測試
(1)將本地計算機的端口80上的Web服務器公開到互聯網:
ngrok http
8080
(2)ngrok提供了一個實時的Web UI,您可以在其中內省您的隧道上運行的所有HTTP流量。在啟動ngrok之后,只需在Web瀏覽器中打開http://localhost:4040即可檢查請求詳細信息。
http://localhost:4040/
http://localhost:8080/cars
3、Python線程
3.1 _thread模塊
_thread實現多線程主要通過: _thread.start_new(執行的方法的名稱,當前執行方法需要的參數)
import _thread
import time
def print_time ( thread_name
, delay
) : count
= 0 while count
< 5 : time
. sleep
( delay
) count
+= 1 print ( "線程名:{0},當前的時間為:{1}" . format ( thread_name
, time
. strftime
( "%Y-%m-%d %H:%M:%S" , time
. localtime
( ) ) ) )
try : _thread
. start_new_thread
( print_time
, ( "Thread-1" , 2 ) ) _thread
. start_new_thread
( print_time
, ( "Thread-2" , 4 ) )
except : print ( "Error :線程無法啟動線程" ) while 1 : pass
_thread加鎖:
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
( ) lock
. acquire
( ) loop_locks
. append
( lock
) for i
in nloops
: _thread
. start_new
( loop_func
, ( i
, loop_times
[ i
] , loop_locks
[ i
] ) ) for i
in nloops
: while loop_locks
[ i
] . locked
( ) : pass print ( "all DONE at:{0}" . format ( ctime
( ) ) ) if __name__
== "__main__" : main
( )
3.2 threading模塊
更高級的threading模塊。 通過threading.Thread(執行的函數,name=“執行線程的名稱”,args=(執行函數需要的參數))創建一個可執行的線程。
import threading
import time
class Sum : count
= 0 def loop_func ( ) : while Sum
. count
< 10 : time
. sleep
( 1 ) Sum
. count
+= 1 current_name
= threading
. currentThread
( ) . getName
( ) current_time
= time
. strftime
( "%Y-%m-%d %H:%M:%S" , time
. localtime
( ) ) print ( "{0}:當前執行操作的時間:{1},當前count的結果為:{2}" . format ( current_name
, current_time
, Sum
. count
) ) def main ( ) : threading
. Thread
( target
= loop_func
, name
= "線程一" ) . start
( ) threading
. Thread
( target
= loop_func
, name
= "線程二" ) . start
( ) threading
. Thread
( target
= loop_func
, name
= "線程三" ) . start
( ) if __name__
== '__main__' : main
( )
結語
如果您覺得該方法或代碼有一點點用處,可以給作者點個贊,或打賞杯咖啡;╮( ̄▽ ̄)╭ 如果您感覺方法或代碼不咋地//(ㄒoㄒ)//,就在評論處留言,作者繼續改進;o_O??? 如果您需要相關功能的代碼定制化開發,可以留言私信作者;(????) 感謝各位大佬童鞋們的支持!( ′ ▽′ )ノ ( ′ ▽′)っ!!!
總結
以上是生活随笔 為你收集整理的【Web开发】Python实现Web图表功能(D-Tale入门) 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。