- Jan 09 Tue 2018 10:36
-
利用雙向佇列來實現大樂透方式
- Dec 18 Mon 2017 20:59
-
如何利用windows 工作排程器,讓python自動執行程式

在工作排程器裡,工作的內容,其中動作視窗有三個參數需要設置。
第一個,是python執行檔所在的位置,以上圖為例,為 c:\program files\python35\python.exe
(前後有沒有雙引號是不影響執行結果的)
第二個,是python檔案所在的完整路徑,以上圖為例,為d:\python\helloworld.py
第三個,是python檔案所在的目錄,以上圖為例,為d:\python\
如果沒有設置第三個,那麼工作排程器會預設一開始的路徑為 c:\windows\system32\
也因此,python檔案若有要輸出檔案,若沒有指定絕對路徑,檔案會放在 c:\windows\system32\目錄下。
- Dec 16 Sat 2017 22:09
-
如何讓matplotlib所生成的圖形裡中文不出現亂碼
用記事本開啟matplotlibrc 我的路徑如下:C:\Anaconda3\Lib\site-packages\matplotlib\mpl-data\matplotlibrc
將下面三行前面的#取消
font.family : sans-serif
font.serif : DejaVu Serif, Bitstream Vera Serif, ……
axes.unicode_minus : False ………
將下面三行前面的#取消
font.family : sans-serif
font.serif : DejaVu Serif, Bitstream Vera Serif, ……
axes.unicode_minus : False ………
- Nov 30 Thu 2017 14:19
-
如何利用pandas 刪除excel每張表格最後一列
- Nov 30 Thu 2017 10:02
-
如何讀取奇摩股市iframe中非同步的資料

#說明上圖中k值及d值是透過javascript採非同步傳輸方式,將資料載入至iframe框架中,若直接使用requests.get()的話,是拿不到裡面資料的。
# -*- coding: utf-8 -*-
import time,os
from selenium import webdriver #載入selenium模組
driver=webdriver.PhantomJS(r'c:\phantomjs.exe') #啟動web browser模擬器
driver.get("https://tw.screener.finance.yahoo.net/screener/check.html?symid=2029")
try:
driver.switch_to_frame('screenercheck') #切換到frame框架中,括號中的內容是iframe's id
a=driver.find_element_by_id('Kline')
b=driver.find_element_by_id('Dline')
print(a.text,b.text)
finally:
driver.quit()
time.sleep(2)
- Nov 24 Fri 2017 15:39
-
如何讀取excel某一列的資料
- Nov 24 Fri 2017 12:02
-
如何讀取excel 整張sheet工作表的內容
- Nov 24 Fri 2017 11:47
-
如何將資料寫入excel檔中

import openpyxl,os
def inputData():
dirpath=os.getcwd()+'/' #取得目前工作路徑
filename='test.xlsx'
fullpath=os.path.join(dirpath,filename)
wb=openpyxl.load_workbook(filename)
ws=wb.get_sheet_by_name('test') #取得工作表test
data=['apple','orange','banana','gruva','grape']
d=iter(data) #將串列資料置入迭代器中
for row in ws['a1':'e1']:
try:
for cell in row:
cell.value=next(d) #因為迭代器到末端之後再呼叫會出現錯誤,所以以try…except的方式來執行,忽略報錯
except:
pass
- Nov 15 Wed 2017 17:07
-
利用win32com開啟word文件並修改後,進行存檔
from win32com import client
import os
docApp=client.Dispatch('Word.Application')
cpath=os.path.dirname(__file__)
doc=docApp.Documents.Open(cpath+r"\doc\text.docx") #與word應用程式連結,並產生word物件
range1=doc.Range(doc.Content.Start,doc.Content.End) #把原文件的內容傳給range1
range1.InsertAfter(",別懷疑,有很多人都是這麼相信的") #在range1變數的後面新增文字
doc.Content=range1 #把變數range1的內容指定給原文件
doc.Save() #存檔
doc.Close()
docApp.Quit()
import os
docApp=client.Dispatch('Word.Application')
cpath=os.path.dirname(__file__)
doc=docApp.Documents.Open(cpath+r"\doc\text.docx") #與word應用程式連結,並產生word物件
range1=doc.Range(doc.Content.Start,doc.Content.End) #把原文件的內容傳給range1
range1.InsertAfter(",別懷疑,有很多人都是這麼相信的") #在range1變數的後面新增文字
doc.Content=range1 #把變數range1的內容指定給原文件
doc.Save() #存檔
doc.Close()
docApp.Quit()
- Nov 15 Wed 2017 15:26
-
使用win32com套件,新增一個word的文件,並加入內容
#---------------新增的個空的word 文件-------------------------------
import win32com,os #載入win32,os模組
from win32com.client import *
import win32com,os #載入win32,os模組
from win32com.client import *
- Nov 15 Wed 2017 11:04
-
使用bokeh套件繪製圖表

from bokeh.plotting import figure,show,output_file
output_file('lineout.html') #輸出成html檔,檔名為lineout.html
p=figure(width=800,height=400,title='零用金統計表') #圖表尺寸大小為800×400
p.title.text_color='green' #圖表標題顏色為綠色,字體大小為18
p.title.text_font_size='18pt'
p.xaxis.axis_label='年齡' #x座標名稱
p.yaxis.axis_label='零用金' #y座標名稱
listx1=[1,5,7,9,13,16] #x座標資料
listy1=[15,30,50,60,80,90] #y座標資料
dashs=[12,4] #虛線顯示點數,第一個是顯示點數為12,而空白點數為4點
p.line(listx1,listy1,line_width=4,line_color='red',line_alpha=0.3,line_dash=dashs,legend='男性') #legend是圖例所顯示的內容
listx2=[2,6,8,11,14,16]
listy2=[10,40,30,50,80,60]
p.line(listx2,listy2,line_width=4,line_color='blue',legend='女性')
show(p)
- Nov 10 Fri 2017 00:00
-
利用requests、beautifulsoup、一層一層的往下找資料,以樂透彩網站為例

#查找49樂合彩本期號碼
import requests
from bs4 import BeautifulSoup as bs
url='http://www.taiwanlottery.com.tw/'
html=requests.get(url) #取得樂透彩網站html內容
html.encoding='utf8'
sp=bs(html.text,'html.parser') #使用beautifulsoup套件來解析網頁內容
data1=sp.select('table') #將所有的表格,取出,存成list
data2=data1[3].find_all('span') #比對樂和彩表格是第幾個表格,並將表格內所有的<span>為開頭的全找出來
print("本期樂合彩開獎號碼".center(30))
print("="*40)
for i in range(3,9):
print(data2[i].text.strip(),end=' ') #列印內容
print()
for i in range(11,17):
print(data2[i].text.strip(),end=' ')
print("開獎順序")
print("="*40)

