<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>資料分析 &#8211; FinLab</title>
	<atom:link href="https://www.finlab.tw/tag/%E8%B3%87%E6%96%99%E5%88%86%E6%9E%90/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.finlab.tw</link>
	<description>深入淺出的量化投資，讓你在在茫茫股海中，找到專屬於自己的投資方法</description>
	<lastBuildDate>Sat, 18 Jun 2022 21:39:22 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.9</generator>

<image>
	<url>https://www.finlab.tw/wp-content/uploads/2020/07/favicon.png</url>
	<title>資料分析 &#8211; FinLab</title>
	<link>https://www.finlab.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">179699571</site>	<item>
		<title>股價淨值比能找到好股票？用歷史數據讓你感受它的厲害！</title>
		<link>https://www.finlab.tw/pb-data-analysis-explain/</link>
					<comments>https://www.finlab.tw/pb-data-analysis-explain/#respond</comments>
		
		<dc:creator><![CDATA[FinLab - 韓承佑]]></dc:creator>
		<pubDate>Thu, 23 Jul 2020 00:03:00 +0000</pubDate>
				<category><![CDATA[基本面分析]]></category>
		<category><![CDATA[股票策略]]></category>
		<category><![CDATA[股價淨值比]]></category>
		<category><![CDATA[股票]]></category>
		<category><![CDATA[股票分析]]></category>
		<category><![CDATA[資料分析]]></category>
		<category><![CDATA[量化投資]]></category>
		<guid isPermaLink="false">http://34.96.136.135/?p=337</guid>

					<description><![CDATA[股價淨值比(PB)，可以用來判斷公司是被高估還是低估，簡單來說，有點像是股票的 CP 值（但是反著看），股價淨值比小於1代表划算的生意，大於1則是賠本生意。更深入一點的講法，就是公司「股市中的總價值」除以「實體的價值」，其中「股市中的總價值」就是股價X發行量，也就是市值。而「實體價值」就是指不動產 廠房及設備、債務...等的總價值，也就是資產負債相底後，真正留下的價值。]]></description>
										<content:encoded><![CDATA[
<p>股價淨值比(Price-Book Ratio PB)，可以用來判斷公司是被高估還是低估，也可以用來做出很厲害的選股策略！這篇文章會帶大家用數據來玩轉股價淨值比！讓你對股價淨值比「有感覺」！</p>



<h3>股價淨值比 PB 是什麼？</h3>



<p>簡單來說，股價淨值比像是股票的 CP 值。更深入一點的講法，就是</p>



<p>公司的「股市中的總價值」（市值） / 「資產負債的總價值」（淨值）</p>



<p>其中「股市中的總價值」就是股價乘以發行量，也就是市值。而「實體價值」就是指不動產 廠房及設備、債務&#8230;等的總價值，也就是資產負債相底後，真正留下的價值。也有人會寫成「股價/每股淨值」等於分子分母都除以股票發行量。</p>



<h4>股價淨值比也透露股票的「未來價值」</h4>



<p>投資人的樂觀與悲觀，都會影響 PB 的大小，當某當公司股票前景樂觀，投資人會預期公司營利，則股價推升，造成股價淨值比變高，然而反之投資人對公司前景悲觀，則股價淨值比會偏低。換句話說，股價淨值比就是投資人對於該公司的未來看好還是看壞，代表投資人對於該公司的「未來價值」的共識！</p>



<p>有了理論，還得有數據佐證，讓 FinLab 用最清晰的圖表分析，讓你對股價淨值筆的數值「有感覺」！以下就是 2020 年 6 月 30 號，台灣上市上櫃所有的公司，股價淨值比分佈圖：</p>



<figure class="wp-block-image size-large"><img width="1024" height="505" src="https://34.80.70.15/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.40.18-PM-1024x505.png" alt="股價淨值比" class="wp-image-341" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.40.18-PM-1024x505.png 1024w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.40.18-PM-300x148.png 300w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.40.18-PM-768x379.png 768w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.40.18-PM-1536x757.png 1536w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.40.18-PM.png 1890w" sizes="(max-width: 1024px) 100vw, 1024px" title="股價淨值比能找到好股票？用歷史數據讓你感受它的厲害！ 1"><figcaption>股價淨值比分佈圖</figcaption></figure>



<p>你可能會覺得奇怪，為什麼大部份的股票，股價淨值比都大於1呢？大部分股票都偏貴嗎？不是的，這是因為股票是先行反映了此公司的「未來價值」，一家公司只要有營收，就可以用來茁壯，就會成長，所以股價淨值比大於 1 並不會奇怪，因為公司規模都是從小慢慢養大的，反而小於 1 才奇怪，因為代表公司可能有一些財務問題，或是負面新聞導致的，所以看到一家公司股價淨值比低，不是貿然就買進，必須找到下跌的原因，並判斷是否對公司未來有長遠的影響，才能安心買進呀！</p>



<p>雖然股價淨值比低，代表投資人對於某檔股票悲觀，但好處是，你可以用更便宜的價格買到它！相反的，投資人對於股票價格過於樂觀，大家瘋搶，造成股價淨值比過高，暗示買入的價格可能太昂貴囉！</p>



<h3>用數據驗證坊間的謠傳</h3>



<p>坊間謠傳，股價淨值比越小越好，代表該股票買入成本很低，買的比較划算！為了驗證這個說法，可以來設計一個簡單的實驗試試看！</p>



<h4><strong>實驗素材</strong></h4>



<p>為了做一個實驗，必須取得以下的資料，進行回測：</p>



<ol><li><strong>股價淨值比</strong>：可以從<a rel="noreferrer noopener" href="https://www.twse.com.tw/zh/page/trading/exchange/BWIBBU_d.html" target="_blank">公開資訊觀測站</a>，來得到股價淨值比「每日」的數值，其算法的由來，就是由每日的「股價」除以最新季度財報中的「每股淨值」。</li><li><strong>盤後收盤價</strong>：除了上述股價淨值比，公開資訊觀測站還提供「<a rel="noreferrer noopener" href="https://www.twse.com.tw/zh/page/trading/exchange/MI_INDEX.html" target="_blank">每日收盤價</a>」，可以將2004年到現在的收盤價都抓下來。</li><li><strong>除權息歷史紀錄</strong>：雖然可以由收盤價的漲跌來算出報酬率，但是由於除權息的關係，報酬率會失真，所以額外需要「<a rel="noreferrer noopener" href="https://www.twse.com.tw/zh/page/trading/exchange/TWT49U.html" target="_blank">除權息歷史紀錄</a>」來計算調整後的收盤價，才能更準確反應報酬率。</li></ol>



<p>假如你覺得自己處理這些資料很麻煩，也可以參考FinLab的課程，裡面都有提供喔！（置入性行銷&#8230;嘿嘿）</p>



<p>但最簡單的方法，還是使用我們所提供的 <a href="https://www.finlab.tw/%e5%8f%b0%e7%81%a3%e8%82%a1%e5%b8%82%e6%9c%80%e5%bc%b7%e7%9a%84-python-package/" data-type="URL" data-id="https://www.finlab.tw/%e5%8f%b0%e7%81%a3%e8%82%a1%e5%b8%82%e6%9c%80%e5%bc%b7%e7%9a%84-python-package/">FinLab Package</a> 啦！</p>



<h4>回測設計</h4>



<ul><li>回測時間：從2000年到2020年</li><li>換股頻率：每一季度（&#8217;03-31&#8242;, &#8217;06-30&#8242;, &#8217;09-30&#8242;, &#8217;12-31&#8217;）</li><li>選股策略：將所有上市上櫃的股票，股價淨值比由小到大，分成均衡數量五等份，第一個投資組合的是股價淨值比小於 20％的股票，而第二種策略則是 股價淨值比介於 20％～40％的股票，以此類推。</li></ul>



<figure class="wp-block-image size-large"><img loading="lazy" width="700" height="450" src="https://34.80.70.15/wp-content/uploads/2020/07/newplot-4.png" alt="newplot 4" class="wp-image-338" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/newplot-4.png 700w, https://www.finlab.tw/wp-content/uploads/2020/07/newplot-4-300x193.png 300w" sizes="(max-width: 700px) 100vw, 700px" title="股價淨值比能找到好股票？用歷史數據讓你感受它的厲害！ 2"><figcaption>五組股票不同的報酬率</figcaption></figure>



<p>這張圖的 Y 軸是從 2004 年開始投資，資產的倍數變化圖，可以發現股價淨值比低於全體的 20% 的股票組合（藍色），真的比其他組合的報酬率來要好，但這邊的回測是一群股票的整體結果，由於樣本數量夠大，才能發現這樣的現象。</p>



<h4>究竟股價淨值比選多少比較安全呢？</h4>



<p>結合上述的實驗結果，可以做圖繪製出「每段時間的股價淨值比中位數」：</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="484" src="https://34.80.70.15/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.29.02-PM-1024x484.png" alt="Screen Shot 2020 07 03 at 6.29.02 PM" class="wp-image-340" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.29.02-PM-1024x484.png 1024w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.29.02-PM-300x142.png 300w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.29.02-PM-768x363.png 768w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.29.02-PM-1536x726.png 1536w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-03-at-6.29.02-PM.png 1996w" sizes="(max-width: 1024px) 100vw, 1024px" title="股價淨值比能找到好股票？用歷史數據讓你感受它的厲害！ 3"><figcaption>上市上櫃股價淨值比中位數</figcaption></figure>



<p>由上圖中可以發現，股價淨值比的中位數是「隨時間浮動的」！也就是，當牛市時，全體國民瘋搶股票，造成很多雞蛋水餃股，股價莫名其妙衝很高；另外當熊市時，很多很多股票都被打回原形，造成股價淨值比中位數來到 1 左右，甚至在 2008 金融海嘯時，比 1 還小！所以股價淨值比的高低是「相對的」，也就是說，股價淨值比小於 1.5 不帶表划算，例如當金融海嘯時，超過一半的股票 PB 都小於 0.7，所以<strong><em>不能用絕對的數值來判斷股價淨值比</em></strong>，而是用相對、浮動的百分比，會比較妥當喔！到底要怎麼用來選股，賣個關子，看到最後再告訴你。</p>



<h3>選股價淨值比低的股票，報酬會不會不穩定呢？</h3>



<p>正如剛剛所提及，股價淨值比小於 1 的股票，代表投資人對其公司前景不看好，或沒人關注，那當金融海嘯發生時，這些淨值低的股票，會不會有倒閉的風險呢？為了回答這個問題，像剛剛一樣，將股票的股價淨值比從小到大，切成五等份，持有一個季度，並衡量每個季度的報酬率：</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="471" src="https://34.80.70.15/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-12.55.44-AM-1024x471.png" alt="Screen Shot 2020 07 04 at 12.55.44 AM" class="wp-image-344" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-12.55.44-AM-1024x471.png 1024w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-12.55.44-AM-300x138.png 300w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-12.55.44-AM-768x353.png 768w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-12.55.44-AM-1536x707.png 1536w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-12.55.44-AM-2048x942.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" title="股價淨值比能找到好股票？用歷史數據讓你感受它的厲害！ 4"><figcaption>股價淨值比從小到大分成五份，持有一季的報酬率</figcaption></figure>



<p>上圖 Y 軸是報酬率，0.1 代表賺 10% 的意思。你會發現，當股價淨值比小的股票組合（PB &lt; 20%，上圖藍色），在2007年股市泡沫時，有異常很好的表現（圖中最高的藍色棒子），報酬率來到了50％/季，畢竟大家熱炒一波，便宜股雞犬升天，變成高價股，是很正常的！那下跌的時候呢？可以看到當 2008 年下跌時，低股價淨值比的股票並沒有跌得很嚴重！為什麼會這樣呢？</p>



<h3>照理說不被看好的股票應該會跌的更嚴重吧？</h3>



<p>還記得剛剛所提及的「股價淨值比中位數」嗎？由於金融海嘯時，股價淨值比中位數（50％）來到了 0.7 這麼小，更何況是小於 20％ 的股票，據統計，2008年股價淨值比 20％ 的絕對數值，只剩下 0.39 ！也就是股價淨值比低於 0.39 才有可能被選入持股中，相信這些股票是已經跌到「跌無可跌」的地步了吧！</p>



<p>所以我們就要選擇低股價淨值比的股票囉？等等&#8230;別著急，先來看看</p>



<h3>低股價淨值比的股票 &#8211; 近年表現如何？</h3>



<p>上面的圖表，是考慮了 2008 年金融海嘯時的狀況，那假如是近幾年呢？近幾年的報酬率表現如下：</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="467" src="https://34.80.70.15/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-1.11.11-AM-1024x467.png" alt="Screen Shot 2020 07 04 at 1.11.11 AM" class="wp-image-345" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-1.11.11-AM-1024x467.png 1024w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-1.11.11-AM-300x137.png 300w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-1.11.11-AM-768x350.png 768w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-1.11.11-AM-1536x700.png 1536w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-1.11.11-AM.png 2040w" sizes="(max-width: 1024px) 100vw, 1024px" title="股價淨值比能找到好股票？用歷史數據讓你感受它的厲害！ 5"><figcaption>股價淨值比每一季的表現</figcaption></figure>



<p>上圖中可以發現，在 2017 年和 2018 年，低股價淨值比，也就是藍色代表的報酬率，明顯高於其他的股票，但是 2019 和 2020 年則沒有表現得特別好，甚至在這次疫情下，下跌的最多，而反彈的卻不夠多！大致上來說，可以發現 2019 年以後 股價淨值比的表現並沒有特別突出或是特別差，變成一個比較中性的指標。</p>



<h2>為何股價淨值比，在 2020 疫情期間表現不好？</h2>



<p>總結了以下三點，說明股價淨值比近期表現不太理想的原因：</p>



<ul><li>股價淨值比越來越多人使用，市場效率變高，這個指標越來越不顯著。</li><li>在 2013 年、2004 年 也出現過股價淨值比失效的狀況，也可以說每一種指標，都有失效的時候，不是全年無休一直都有效果，說不定之後又生效了也不一定。</li><li>但很大的因素，是因為疫情之下，上漲的都是生技股，而生技股的股價淨值比，由於體質關係，本來就會高於平均的緣故，例如以 2020 年 6 月 30 號的統計，技股平均股價淨值比：3.07，遠高於整體的平均：2.2，由於領漲的都是生技股，所以自然「高股價淨值比」看起來報酬率比較好。</li></ul>



<p>由上述結論其實可以看出，選股其實也很偏重題材的，畢竟只要題材有了，股價淨值比也是可以忽略不計，當作沒看到都可以！然而假如想要建立一個長久有效的選股模型，相信股價淨值比是不會被取代的，相信時間會還給股價淨值比一個公道。</p>



<h3>低股價淨值比策略實戰</h3>



<p>有用的策略，只要一句話就瞭解：</p>



<blockquote class="wp-block-quote"><p><strong><em>找出股票價格大於5，股價在季線之上，且（股價淨值比 X 股價） 最小的20檔股票，持有一個季度</em></strong></p><cite>FinLab 策略庫</cite></blockquote>



<p><strong>太簡單了吧！？</strong>就是要這麼簡單呀！</p>



<p>有時候，投資搞太複雜，看完型態學，又分析價量，再觀察籌碼分析，最後還是被自己的人性所打敗。這樣盲目照著各方說法操作，只會讓你覺得股市就像大海，載浮載沈。FinLab 主張，策略簡單，邏輯粗暴，無腦複製，讓你有時間多陪陪自己的家人，多出去戶外運動。投資不複雜，<strong><em>複雜的是人心，也就是看到這篇文章，卻沒有行動的你。</em></strong></p>



<p>回測後，結果如下圖所示，這是一個非常簡單的策略，一年調整四次，卻可以有非常可觀的歷史報酬率（ 2000 至今有 2000％！），美中不足的是， 2004 年跟 2008 年大跌，最大跌幅（maximum drawdown）來到了 &#8211; 60%，另外，這個策略所買的股票，成交量很小，所以餵納量可能不夠大，假如你的資本太大的話，可能會不適用。假如你手邊資金小，那此策略應該是，可以用<a rel="noreferrer noopener" href="https://www.cmoney.tw/vt/" target="_blank">股市大富翁</a>試試看此策略！至於避開大盤大跌的方法，就讓我留到下一篇吧！</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="1024" height="612" src="https://34.80.70.15/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-2.24.04-AM-1024x612.png" alt="Screen Shot 2020 07 04 at 2.24.04 AM" class="wp-image-347" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-2.24.04-AM-1024x612.png 1024w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-2.24.04-AM-300x179.png 300w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-2.24.04-AM-768x459.png 768w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-2.24.04-AM-1536x918.png 1536w, https://www.finlab.tw/wp-content/uploads/2020/07/Screen-Shot-2020-07-04-at-2.24.04-AM.png 1616w" sizes="(max-width: 1024px) 100vw, 1024px" title="股價淨值比能找到好股票？用歷史數據讓你感受它的厲害！ 6"><figcaption>策略回測結果</figcaption></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://www.finlab.tw/pb-data-analysis-explain/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">337</post-id>	</item>
		<item>
		<title>只用一行程式碼分析數據!? &#8211; 實用的 Python Package</title>
		<link>https://www.finlab.tw/one-line-info-dataframe/</link>
					<comments>https://www.finlab.tw/one-line-info-dataframe/#respond</comments>
		
		<dc:creator><![CDATA[FinLab - 韓承佑]]></dc:creator>
		<pubDate>Tue, 21 Jul 2020 14:43:09 +0000</pubDate>
				<category><![CDATA[財經PYTHON教學]]></category>
		<category><![CDATA[DATAFRAME]]></category>
		<category><![CDATA[PYTHON]]></category>
		<category><![CDATA[機器學習]]></category>
		<category><![CDATA[資料分析]]></category>
		<guid isPermaLink="false">http://34.96.136.135/?p=984</guid>

					<description><![CDATA[這篇文章介紹一個好用的 package，只要一行，就可以做出精美、詳細的圖表分析，還可以幫你查看資料是否有缺漏和錯誤的情況！]]></description>
										<content:encoded><![CDATA[
<p>這篇文章介紹一個好用的 package，只要一行，就可以做出精美、詳細的圖表分析<br>還可以幫你查看資料是否有缺漏和錯誤的情況！<a href="https://www.finlab.tw/one-line-info-dataframe/thumbnail.jpeg"></a></p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="1024" height="683" src="http://34.96.136.135/wp-content/uploads/2020/07/thumbnail-6-1024x683.jpeg" alt="thumbnail 6" class="wp-image-985" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/thumbnail-6-1024x683.jpeg 1024w, https://www.finlab.tw/wp-content/uploads/2020/07/thumbnail-6-300x200.jpeg 300w, https://www.finlab.tw/wp-content/uploads/2020/07/thumbnail-6-768x512.jpeg 768w, https://www.finlab.tw/wp-content/uploads/2020/07/thumbnail-6-1536x1024.jpeg 1536w, https://www.finlab.tw/wp-content/uploads/2020/07/thumbnail-6.jpeg 1650w" sizes="(max-width: 1024px) 100vw, 1024px" title="只用一行程式碼分析數據!? - 實用的 Python Package 7"></figure></div>



<p>今天的程式碼成果：<a href="https://www.finlab.tw/one-line-info-dataframe/profile_df.gif"></a></p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="600" height="338" src="http://34.96.136.135/wp-content/uploads/2020/07/profile_df.gif" alt="profile df" class="wp-image-986" title="只用一行程式碼分析數據!? - 實用的 Python Package 8"></figure></div>



<h1 id="先取得要分析之資料">先取得要分析之資料</h1>



<p>今天我們來分析一下股票的本益比、股價淨值比和殖利率，<br>先提供給大家一個爬蟲，讓大家可以直接把資料爬下來：</p>



<pre class="wp-block-code"><code class="">import datetime
import pandas as pd
import warnings
import requests
from io import StringIO
import pandas_profiling

def crawler(date):
    datestr = date.strftime('%Y%m%d')
    url = 'https://www.twse.com.tw/exchangeReport/BWIBBU_d?response=csv&amp;date='+datestr+'&amp;selectType=ALL'
    res = requests.get(url)
    df = pd.read_csv(StringIO(res.text), header=1)
    df['本益比'] = pd.to_numeric(df['本益比'], errors='coerce')
    
    return df.dropna(thresh=3).dropna(thresh=0.8, axis=1)</code></pre>



<p>接下來我們就呼叫&nbsp;<code>crawler</code>&nbsp;這個函式，就可以將財務數據資料都爬取下來囉！</p>



<pre class="wp-block-code"><code class="">df = crawler(datetime.date(2019,10,7))
df.head()</code></pre>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="1024" height="190" src="http://34.96.136.135/wp-content/uploads/2020/07/head-1024x190.png" alt="head" class="wp-image-988" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/head-1024x190.png 1024w, https://www.finlab.tw/wp-content/uploads/2020/07/head-300x56.png 300w, https://www.finlab.tw/wp-content/uploads/2020/07/head-768x143.png 768w, https://www.finlab.tw/wp-content/uploads/2020/07/head-1536x285.png 1536w, https://www.finlab.tw/wp-content/uploads/2020/07/head-2048x380.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" title="只用一行程式碼分析數據!? - 實用的 Python Package 9"></figure></div>



<p><a href="https://www.finlab.tw/one-line-info-dataframe/head.png"></a></p>



<h3 id="1-用舊的方法來分析資料">1. 用舊的方法來分析資料</h3>



<p>最簡單的方式，假如有用過&nbsp;<code>pandas</code>&nbsp;的大家應該都知道，<br>可以使用&nbsp;<code>df.describe()</code>&nbsp;來大致上觀察數據的樣貌<br>假如你對 pandas 不太熟悉，它有點像是拿來處理表格的資料，<br>就像是 python 界的 excel 一樣，雖然它非常好用，但是有點太古老（無聊）了！</p>



<pre class="wp-block-code"><code class="">df.describe()</code></pre>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="1024" height="262" src="http://34.96.136.135/wp-content/uploads/2020/07/describe-2-1024x262.png" alt="describe 2" class="wp-image-990" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/describe-2-1024x262.png 1024w, https://www.finlab.tw/wp-content/uploads/2020/07/describe-2-300x77.png 300w, https://www.finlab.tw/wp-content/uploads/2020/07/describe-2-768x196.png 768w, https://www.finlab.tw/wp-content/uploads/2020/07/describe-2-1536x393.png 1536w, https://www.finlab.tw/wp-content/uploads/2020/07/describe-2-2048x524.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" title="只用一行程式碼分析數據!? - 實用的 Python Package 10"></figure></div>



<p><a href="https://www.finlab.tw/one-line-info-dataframe/describe.png"></a></p>



<h3 id="2-酷炫的方法資料分析">2. 酷炫的方法資料分析</h3>



<p>首先我們可以安裝 pandas_profiling</p>



<pre class="wp-block-code"><code class="">pip install pandas_profiling</code></pre>



<p>接下來就可以直接來使用：</p>



<pre class="wp-block-code"><code class="">import pandas_profiling
df = crawler(datetime.date(2019,10,7))
df.profile_report()</code></pre>



<p>然後我們就會看到超精美的圖表！</p>



<h4 id="找出資料的缺漏或問題">找出資料的缺漏或問題</h4>



<p>我覺得&nbsp;<code>pandas_profiling</code>&nbsp;很棒的地方在於，<br>可以將資料一口氣全部統整給我們，方便我們去做資料前處理，<br>例如下圖中的左下角，就可以看到每一個column有哪些警告，<a href="https://www.finlab.tw/one-line-info-dataframe/profile.png"></a></p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="1024" height="562" src="http://34.96.136.135/wp-content/uploads/2020/07/profile-1024x562.png" alt="profile" class="wp-image-991" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/profile-1024x562.png 1024w, https://www.finlab.tw/wp-content/uploads/2020/07/profile-300x165.png 300w, https://www.finlab.tw/wp-content/uploads/2020/07/profile-768x421.png 768w, https://www.finlab.tw/wp-content/uploads/2020/07/profile-1536x843.png 1536w, https://www.finlab.tw/wp-content/uploads/2020/07/profile-2048x1124.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" title="只用一行程式碼分析數據!? - 實用的 Python Package 11"></figure></div>



<ul><li>本益比有 20.4 % 是缺漏的：這是正常情況，因為本益比小於零不顯示</li><li>殖利率有 20.0 % 是 0：這也是正常情況，因為公司不一定有發股利股息</li><li>財報都是用第 2 季的財報：這也是正常的！</li></ul>



<p>有了這種檢驗，更能夠讓我們知道資料的可靠程度，真的非常非常棒！<br>除了上述的檢驗外，我們還可以</p>



<h4 id="輕鬆檢視每一個-column-的資料">輕鬆檢視每一個 column 的資料</h4>



<p>這邊可以看到每一種資料的分佈，可以讓我們更好的掌握數據分佈型態<a href="https://www.finlab.tw/one-line-info-dataframe/hist.png"></a></p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="1024" height="467" src="http://34.96.136.135/wp-content/uploads/2020/07/hist-1-1024x467.png" alt="hist 1" class="wp-image-992" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/hist-1-1024x467.png 1024w, https://www.finlab.tw/wp-content/uploads/2020/07/hist-1-300x137.png 300w, https://www.finlab.tw/wp-content/uploads/2020/07/hist-1-768x350.png 768w, https://www.finlab.tw/wp-content/uploads/2020/07/hist-1-1536x701.png 1536w, https://www.finlab.tw/wp-content/uploads/2020/07/hist-1.png 1964w" sizes="(max-width: 1024px) 100vw, 1024px" title="只用一行程式碼分析數據!? - 實用的 Python Package 12"></figure></div>



<h4 id="檢視資料相關性">檢視資料相關性</h4>



<p>這邊還可以檢視資料的相關性，這邊有些複雜的名詞，哪天再來跟各位介紹<a href="https://www.finlab.tw/one-line-info-dataframe/corr.png"></a></p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="1024" height="471" src="http://34.96.136.135/wp-content/uploads/2020/07/corr-1024x471.png" alt="corr" class="wp-image-993" srcset="https://www.finlab.tw/wp-content/uploads/2020/07/corr-1024x471.png 1024w, https://www.finlab.tw/wp-content/uploads/2020/07/corr-300x138.png 300w, https://www.finlab.tw/wp-content/uploads/2020/07/corr-768x353.png 768w, https://www.finlab.tw/wp-content/uploads/2020/07/corr-1536x706.png 1536w, https://www.finlab.tw/wp-content/uploads/2020/07/corr-2048x941.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" title="只用一行程式碼分析數據!? - 實用的 Python Package 13"></figure></div>



<p><code>pandas_profiling</code>&nbsp;真的是很不錯的 package，<br>可以幫我們進一步的認識資料，<br>假如你也覺得這個 package 很實用，<br>也歡迎你分享給大家喔！</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.finlab.tw/one-line-info-dataframe/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">984</post-id>	</item>
	</channel>
</rss>
