Giter VIP home page Giter VIP logo

Comments (37)

arleigh418 avatar arleigh418 commented on June 7, 2024

Hi,您好,很高興您提問。
但我需要多一點點線索,從圖來看應該是stock_list.py這只程式,獲取台股列表。
從您print出來的東西來看,看起來程式只運行到了將上市日為空的部分轉為NaN

x['上市日'] = pd.to_datetime(x['上市日'], errors='coerce')

但後續還有許多動作,是清除Nan值並保留我想留下的欄位。

#把上市日的Nan去掉即可 x = x.dropna(subset=['上市日'])
#Drop掉不要的欄位 x = x.drop(['有價證券代號及名稱', '國際證券辨識號碼(ISIN Code)', 'CFICode','備註'], axis=1)
#更換剩餘的欄位順序 x = x[['代號','股票名稱', '上市日', '市場別', '產業別']] ......

我不確定問題是出在哪裡,您能夠貼上程式或是您運行的順序之類的嗎?
我完整的照著程式跑的確會如期產生一份股票清單。

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

想問沒有轉檔成excel檔,沒有響應是因為不是我打的程式都能應用轉成excel嗎
P_20210928_232650_1_1
P_20210928_232557_1

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

Hi 您好,
很高興您提問,您的問題是出在data這個變數,data這個變數在您的例子中是response類,response類是源自於requests請求網址時所賦值的,如下:
data = requests.get(f'https://www.twse.com.tw/fund/T86?response=json&date={r_date}&selectType=ALLBUT0999&_=1614316365630')

您程式的問題是在於您的位階出了問題,您仔細看下面這一段的位階,也就是您程式的倒數第二三行,他是被包在函數twse_data裡面,換言之您並沒有呼叫到twse_data這個函示。
data=twse_data('20210928')

解決方式就是您需要將倒數第三行的data=twse_data('20210928')與倒數第二行這兩段提到最外面的階層,也就是前面不能有任何空白,才算是成功呼叫了twse_data函式,data這個變數才會被賦值成dataframe而您才能夠進行存檔的動作。

另外小提醒一點,to_excel最好是用做如.xlsx的檔案,而to_csv則是用做.csv的檔案。

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

想請問為什麼會屬性錯誤
https://user-images.githubusercontent.com/91065933/135715155-790ce49a-417b-4ba1-b012-ddf9366b6fd1.jpg
https://user-images.githubusercontent.com/91065933/135715170-5fdf6c11-e263-49ed-87af-2c968097c38e.jpg
print('AttributeError')
試過使用這種方式還是沒辦法
另外pip install yfinance==0.1.63
這個也有試過了
想請你幫我看一下 謝謝

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

您好,很高興您的提問。
該錯誤發生的原因有很多,不過9成的問題都是出在您的本地檔案有個與該套件同名的py檔。
換言之您是否自己創立過叫做yfinance.py諸如此類的檔案? 創建自行開發的py檔時請勿與套件名稱重複。
例如您要練習pandas套件的檔案,就盡量不要取一個叫做pandas.py的檔案,會引發類似錯誤。

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

是的,我猜測是如此,先將您創建的yfinance.py的檔案先刪除 (您創建的,不是套件裡面的)
嘗試看看是否有改善,若錯誤仍然存在,我們再來討論看看如何解決

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

您好,有圖片可以參考嗎?

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

您可能需要重新再貼一次哦~我好像沒看到程式或圖片

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

很抱歉,仍然沒有看到圖喔

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

仍然沒有哦~您自己有看到圖嗎?

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

您在無痕視窗打開一次這個issue (以未登入的狀態查看),看下能不能看到。
您先前貼的圖我都能看到,唯獨這最後一次地看不到,您改變了貼圖片的方式嗎?

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

Hi您好,這兩張圖我能看到了~不過這這個錯誤好像是先前那個檔名不要叫yfinance.py的那個錯誤。
代表此問題仍然存在嗎?

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

https://user-images.githubusercontent.com/91065933/135737568-a1d51f46-d771-459d-abda-f2630a8607ef.jpg
https://user-images.githubusercontent.com/91065933/135737453-2c95c51e-063d-4c14-bc8c-2b92cf832871.jpg
使用
電腦傳送可以看到
使用電腦看不到圖片但手機看的到
非常抱歉

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

https://user-images.githubusercontent.com/91065933/135737632-8af1cc4a-65ff-49d0-bd4c-3657c547cb47.jpg

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

圖片附錯 抱歉
在執行之前已安裝 pip install yfinance
pip show yfinance
pip install yfinance==0.1.63
都嘗試過了

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

很經典的找不到套件錯誤。
初步處理可以先解安裝套件,再重新安裝一次。
pip uninstall yfinance
pip install yfinance

重新安裝後若無法解決,嘗試直接打開cmd,然後輸入python,然後打import yfinance看看是否會成功。
如果cmd打開的python有yfinance,但您用編譯器執行的沒有,那可能還需要知道以下資訊:

  1. 您是否有使用虛擬環境?
  2. 您的電腦是不是有數個Python? 您的編譯器使用的是哪一個Python?
  3. 您是否使用Anaconda?

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

我有按照步驟執行了
接著出現語法錯誤 想知道是哪裡有問
https://user-images.githubusercontent.com/91065933/135741409-698f1ffa-3f05-40e6-93f1-b0b3397f0482.jp
https://user-images.githubusercontent.com/91065933/135741415-4d1bf404-247f-4897-9ab0-a92a30e00c6b.jpg

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

https://user-images.githubusercontent.com/91065933/135741432-8d3b186c-f7c2-46ec-b8df-5b3a66bf3b6b.jpg

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

Hi您好,SyntaxError問題是出在您的程式格式不對,通常是例如多了空白、少了縮排。
總之就是您的程式並未遵守程式語言規範的格式。
但我看您的圖,第一張我看不到,因為只有.jp,檔名錯誤。
第二張就是剛剛提到的SyntaxError問題,但是我看到有一個叫做yfinance.py的檔案,這支是先前我們說最好移除的那支嗎?
第三張看起來沒有任何問題,我猜測是第三張是程式,第二張是執行結果?
但從第二張的執行報錯來看,程式內應該有個except AttributeError ,但我沒有在任何一張圖上看到有這支程式。
我推測問題是您的程式import yfinance,但其實不是import到套件的yfinance,而是import到先前建議您刪除的,您自己創建的yfinance.py。

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

https://user-images.githubusercontent.com/91065933/135743072-cc941c62-2fbb-48a3-acfe-63992b95355f.png
https://user-images.githubusercontent.com/91065933/135743084-12c8a2da-4119-4a45-85f3-b0fd007862eb.png
我在資料夾中刪掉了原本的yfinance.py的檔案
然後也pip install yfinance 也出現下載成功 但執行程式時出現找不到模組

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

https://user-images.githubusercontent.com/91065933/135743184-9df61478-24f8-418b-a300-35b915adce79.png
第一張圖片是這張

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

Hi您好,問題在於您的環境中有多個python,我猜是Anaconda+python?
因為您show出來的pip install 的版本是python3.7版本,但是您的編譯器使用的是3.8.5版本的python。
您的套件都裝在python3.7那裡,但是使用上卻是3.8.5,理所當然無法讀取到套件。
若是您確定您有安裝過Anaconda,且未來也決定使用Anaconda的話,嘗試用conda來裝套件。
conda install yfinance

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

我都是使用Anaconda裡的spyder
但有下載python

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

您好,雖然我對Anaconda不熟悉,但我印象中好像裝了Anaconda就不需要另外去裝Python了。
如果另外去Python官網在裝一次,好像就會有兩個Python共存在電腦中。(Anaconda自帶的+官網下載的)
您嘗試看看conda install看是否可解決問題,若可以以後都使用conda來進行相關作業吧

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

想問刪了Anaconda的話spyder也會一起刪除,這樣有什麼可以打程式的軟體嗎
因為使用vscode問題很多 才使用spyder,之前vscode在執行程式會有問題但使用spyder就不會
https://user-images.githubusercontent.com/91065933/135745843-169def1c-1fc2-44ad-bca5-6176dd24a1c7.png
像這樣

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

就我所知Anaconda的使用者使用Jupyter Notebook為多,您可以去研究看看。

vscode作為主流的編輯器之一,問題肯定是少很多的。

就您的圖片來看應該是使用錯誤,您圖片上的問題顯示data這個變數的NameError,從執行視窗可以看出您只執行的print(data)這一行程式,其餘的完全沒有執行,在您為宣告data這個變數之前就執行print(data),所以引發此錯誤,因此問題應該是在使用上的不熟悉。

您可以考慮看看Jupyter Notebook,主要以您習慣上手的為主。spyder我倒是沒使用過,也沒辦法對其進行評判。

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

我把Anaconda刪掉並重新下在後打pip install yfinance就可以了,雖然我不太確定問題出在哪裡,但在執行程式上可以跑出結果
非常謝謝你的協助

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

Hi 您好,很高興聽到您解決問題了~
問題基本上如我所述,您的電腦同時有兩個Python ,Anaconda(假設稱python-a) +官網下載的Python(假設稱python-b)

而cmd打開使用的pip install 指令是把套件安裝在python-b裡面,spyder屬於Anaconda,所以他運行的是python-a。您會找不到套件原因就在這裡,套件都在python-b底下,而您一直使用的是python-a。

希望這樣能幫助您了解問題,以後遇到能夠更快速解決,通常我認為最根本的解法就是對環境做清理,直白一點就如您的動作,砍掉其中一個。

from python-and-taiwan-stock-market.

houhouryan avatar houhouryan commented on June 7, 2024

想請問如果我只想要小數點後兩位
這樣的語法問題在哪 想請你幫我看一下
https://user-images.githubusercontent.com/91065933/135759109-1f54bde4-5906-467f-966b-72281e3f63c8.png
https://user-images.githubusercontent.com/91065933/135759131-b4fb64f0-9b79-4d0c-8cb8-ee2281e2d208.png

from python-and-taiwan-stock-market.

arleigh418 avatar arleigh418 commented on June 7, 2024

您貼出來的語法毫無問題啊
df = 1.23743xxxxx
df = round(df,2)

結果是1.24,這難道不是您要的取小數點後兩位嗎?

from python-and-taiwan-stock-market.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.