Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pd.to_excel header char vertical

#coding:utf-8
import xlsxwriter
workbook = xlsxwriter.Workbook('d:suq	estdemo1.xlsx') #建立一個excel檔案
worksheet = workbook.add_worksheet('sheet1') #在檔案中建立一個sheet
#border:邊框,align:對齊方式,bg_color:背景顏色,font_size:字型大小,bold:字型加粗 
top=workbook.add_format({'border':6,'align':'center','bg_color':'cccccc','font_size':13,'bold':True}) #設定單元格格式
title=[u'檔案系統',u'總容量',u'使用大小',u'剩餘大小'] #設定第一行標題資訊
buname=['/dev/mapper/vg_basic-lv_root','tmpfs','/dev/sda1'] #設定左邊第一排資訊
worksheet.write_row('A1',title,top)
worksheet.write_column('A2',buname,top)
worksheet.set_column('A:D',40) #A到D列設定寬度,寬度設定必須是整列設定,高度必須是整行設定
#worksheet.set_row(0,40) #設定第一行高度為40畫素
format_data=workbook.add_format({'align':'center','font_size':13}) #設定單元格格式
data=[[17678,4393,12388],[9768,8900,868],[24285,2715,21000]] #模擬檔案系統的資料,data[0],[1],[2]分別表示全部空間,使用空間,剩餘空間
worksheet.write_row('B2',data[0],format_data) #將資料寫入,這裡安裝整行寫入
worksheet.write_row('B3',data[1],format_data)
worksheet.write_row('B4',data[2],format_data)
chart=workbook.add_chart({'type':'column'}) #建立表格,表格型別為column
chart.set_title({'name':u'檔案系統使用率'}) #設定表格的title
for i in ['B','C','D']:
chart.add_series({
'categories': 'sheet1!$A$2:$A$4',
'values':'sheet1!$' i '$2:$' i '$4',
'name':'=sheet1!$' i '$1'
})
#注意上面的表格中,每一行的資料在圖中會顯示在一起,也就是說values為B2:B4
chart.set_size({'width':800,'height':500}) #設定表格的大小
chart.set_y_axis({'name': 'MB'}) #設定表格y軸資訊
#chart.set_style(33) #設定表格的樣式
worksheet.insert_chart('A8',chart) #插入表格
workbook.close()
Comment

PREVIOUS NEXT
Code Example
Python :: python math.trunc 
Python :: pairplot lower triangular 
Python :: python regex type hint 
Python :: splitting Feature and target using iloc 
Python :: FizzBuzz in Python Using String Concatenation 
Python :: flassger 
Python :: parse filename 
Python :: Python getting content from xl range 
Python :: Set symmetric Using the Symmetric Difference Operator (^) Method 
Python :: Find Factors of a Number Using for Loop 
Python :: Simple Python Permutation Without Passing any argument 
Python :: Grading program using if else 
Python :: pyqt global hotkey 
Python :: scikit learn lazy predict 
Python :: passing list vs int in python important 
Python :: vortex core line detection 
Python :: drop columns delta table 
Python :: move python file 
Python :: Python NumPy atleast_3d Function Example when inputs are high dimesion 
Python :: fuck you 
Python :: how to convrete .npz file to txt file in python 
Python :: Python NumPy row_stack Function Syntax 
Python :: Python NumPy dsplit Function 
Python :: Python __sub__ magic method 
Python :: pandas listagg equivalent in python 
Python :: NumPy packbits Syntax 
Python :: selenium python select elements data atribute 
Python :: config.ini list not string 
Python :: python to dart converter 
Python :: find smallest element not present in list python 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =