2023年1月30日 星期一

使用Yahoo Finance套件利用Python來分析亞馬遜股票

 原文:Amazon Stock Analysis in Python with Yahoo Finance

範例1:列出前五天的的交易情形

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pandas as pd
import yfinance as yf
import datetime
from datetime import date, timedelta
import plotly.graph_objects as go
import plotly.express as px
today = date.today()

d1 = today.strftime("%Y-%m-%d")
end_date = d1
d2 = date.today() - timedelta(days=365)
d1 = d2.strftime("%Y-%m-%d")
start_date = d2

data = yf.download('AMZN',
                   start=start_date,
                   end=end_date,
                   progress=False)

data["Date"] = data.index
data = data[["Date", "Open", "High", "Low", "Close", "Adj Close", "Volume"]]
data.reset_index(drop=True, inplace=True)
print(data.head())

執行結果:

範例2: 畫出一年趨勢圖

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pandas as pd
import yfinance as yf
import datetime
from datetime import date, timedelta
import plotly.graph_objects as go
import plotly.express as px
today = date.today()

d1 = today.strftime("%Y-%m-%d")
end_date = d1
d2 = date.today() - timedelta(days=365)
d1 = d2.strftime("%Y-%m-%d")
start_date = d2

data = yf.download('AMZN',
                   start=start_date,
                   end=end_date,
                   progress=False)

data["Date"] = data.index
data = data[["Date", "Open", "High", "Low", "Close", "Adj Close", "Volume"]]
data.reset_index(drop=True, inplace=True)
print(data.head())
figure = go.Figure(data=[go.Candlestick(x=data["Date"],
                                        open=data["Open"], high=data["High"],
                                        low=data["Low"], close=data["Close"])])
figure.update_layout(title = "Amazon Stock Price Analysis",
                     xaxis_rangeslider_visible = False)
figure.show()

執行結果:

範例3:一年長條圖
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import pandas as pd
import yfinance as yf
import datetime
from datetime import date, timedelta
import plotly.graph_objects as go
import plotly.express as px
today = date.today()

d1 = today.strftime("%Y-%m-%d")
end_date = d1
d2 = date.today() - timedelta(days=365)
d1 = d2.strftime("%Y-%m-%d")
start_date = d2

data = yf.download('AMZN',
                   start=start_date,
                   end=end_date,
                   progress=False)

data["Date"] = data.index
data = data[["Date", "Open", "High", "Low", "Close", "Adj Close", "Volume"]]
data.reset_index(drop=True, inplace=True)
print(data.head())
figure = px.bar(data, x="Date", y="Close")
figure.show()

執行結果:

範例4: 使用時間區塊來瞭解某一時段的交易情形

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pandas as pd
import yfinance as yf
import datetime
from datetime import date, timedelta
import plotly.graph_objects as go
import plotly.express as px
today = date.today()

d1 = today.strftime("%Y-%m-%d")
end_date = d1
d2 = date.today() - timedelta(days=365)
d1 = d2.strftime("%Y-%m-%d")
start_date = d2

data = yf.download('AMZN',
                   start=start_date,
                   end=end_date,
                   progress=False)

data["Date"] = data.index
data = data[["Date", "Open", "High", "Low", "Close", "Adj Close", "Volume"]]
data.reset_index(drop=True, inplace=True)
print(data.head())
figure = px.line(data, x='Date', y='Close',
                 title='Stock Market Analysis with Rangeslider')
figure.update_xaxes(rangeslider_visible=True)
figure.show()

執行結果:


2023年1月27日 星期五

Dropzone.js讓網站上拖移文件變得相當容易

 Dropzone.js官方網站:Dropzone.js

範例一:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.2/min/dropzone.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.2/dropzone.min.css">
  </head>
  <body>
	<form action="/file-upload" method="post" enctype="multipart/form-data">
	  <input type="file" name="file" />
	</form>
  </body>
</html>

執行結果:
選取檔案前

選取檔案後

範例二:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<html>
	<head>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.2/min/dropzone.min.js"></script>
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.2/dropzone.min.css">
		<script>
		  Dropzone.options.myGreatDropzone = { // camelized version of the `id`
			paramName: "file", // The name that will be used to transfer the file
			autoProcessQueue: false,
			addRemoveLinks: true,			
			maxFilesize: 2, // MB
		  };
		</script>
	</head>
	<body>
		<form action="/target" class="dropzone" id="my-great-dropzone"></form>
	</body>
</html>

執行結果:
拖移檔案前

拖移檔案後


刪除檔案後



2023年1月14日 星期六

用Python Flask搭配Raspberry pi設計GardenPi 魚菜共生控制系統

今天(2023/1/14)是台灣魚菜共生產業促進會之理監事聯誼會的聚會,因為疫情大家已經有一年沒有一起聚會,2023年對促進會推廣魚菜共生是很重要的,會中大家提出幾項建議,相信在不久後就可以看到促進會的活動。

回想起敏哥參與魚菜共生的學習,要從一位南開畢業生談起,故事發生在10年前(2013年),一位畢業生回來找敏哥,他說想留在老師的實驗室練功學習,老師說可是我付不起您的薪水,只能申請國科會的計畫-銀髮族健康促進暨魚菜共生情境感知系統之研製, 計畫通過後展開大學和農民、社區間的魚菜共生的共學旅程。

2016台北國際發明展_組合架式室內魚菜共生栽培暨情境感知技術_廖俊欽同學(南開科技大學)
台灣魚菜共生產業促進會成立大會圓滿落幕
工作退休但人生不退休 生命的脈動,因為有動而更精彩!

聯誼會結束後,總是想著Python教學,隨手查閱Githup,發現有一套很不錯的開源系統,這套系統是採用Python Flask來開發Web人機介面,利用Raspberry pi來設計控制系統。 GardenPi開源軟體: https://github.com/rjsears/GardenPi

GardenPi開源系統:

(摘自GardenPi開源軟體)

(摘自GardenPi開源系統)

(摘自GardenPi開源系統)