生活随笔 
收集整理的這篇文章主要介紹了
                                
【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 對象。
 
1.2 D-Tale安裝  
pip 
install  dtale
 
 
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安裝即可。數據的導入主要有如下幾種方式:
 
 
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
   (2)安裝您的Authtoken:
   
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實現多線程主要通過:
 
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 
 
 
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模塊。
 
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
( ) 
 
 
結語  
如果您覺得該方法或代碼有一點點用處,可以給作者點個贊,或打賞杯咖啡;╮( ̄▽ ̄)╭
                            總結 
                            
                                以上是生活随笔 為你收集整理的【Web开发】Python实现Web图表功能(D-Tale入门) 的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                            
                                如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。