隨著 Visual Studio 2017 即將正式釋出,C# 7.0 也隨之來到。身為這次的改版,將會帶來許多方便的新功能
if (int.TryParse(input, out var answer))
WriteLine(answer);
else WriteLine("Could not parse input");
一起讓我們來看看 C# 7.0 的威力吧。
在此課程中將帶領對資料分析感到陌生卻又充滿興趣的您,完整地學會運用 R 語言從最初的蒐集資料、探索性分析解讀資料,並進行文字探勘,發現那些肉眼看不見、隱藏在資料底下的意義。此課程主要設計給對於 R 語言有基本認識,想要進一步熟悉實作分析的朋友們,希望在課程結束後,您能夠更熟悉 R 語言這個豐富的分析工具。透過蘋果日報慈善捐款的資料集,了解如何從頭解析網頁,撰寫爬蟲自動化收集資訊;取得資料後,能夠靈活處理資料,做清洗、整合及探索;並利用現成的套件進行文字探勘、文本解析;我們將一步步實際走一回資料分析的歷程,處理、觀察、解構資料,試著看看人們在捐款的決策過程中,究竟是什麼因素產生了影響,以及這些結果又是如何從資料中挖掘而出的呢?
A pH curve is requested for a reaction between 50 mL of 0.2 M HNO3 and 0.1 M NaOH. This involves a neutralization reaction between the acid and base that will result in the pH changing from acidic to basic as the reaction progresses. The curve will track this pH change as the moles of H+ ions are consumed by the OH- ions added from the NaOH.
This document summarizes a titration of 100 mL of 2M HCl with 1M NaOH. It calculates the volume of NaOH needed at the equivalence point as 50 mL. It then sets up the x-axis values from 0 to 100 mL NaOH added in increments of 2 mL. The y-axis values are calculated as the pH at each point using the titration equations before and after the equivalence point.
This document describes how to generate a titration curve for a strong acid-strong base titration using Python. It involves titrating 100 mL of 2 M HCl with 1 M NaOH and plotting the pH as a function of the amount of titrant added. The Python code provided calculates the pH values at different points of titrant addition, plots the curve in three segments before, at, and after the equivalence point, and displays the final titration curve graph.
This document describes an iterative bisection method to find the root of the function 2 * sin(x) + cos(2x) between an initial range. Over 17 iterations, it narrows down the range of r from [4.712389, 6.283185] to [5.908415, 5.908463] by bisection with an allowed error of 1 x 10-5.
21. 7 檔案
世界各國教育支出比例排名 (二)
35
以上每一列資料依次為國名、GDP 百分比、統計年度、註解。資料中
有些國家的名稱可能不只為一個字。若該國家沒有 GDP 百分比時則以
n.a. 替代。
現在我們要撰寫程式重新以 GDP 的百分比由大到小排列,沒有 GDP
百分比的國家排列在最後,同時將資料以橫線替代。此外如果 GDP 百分比
一樣的國家,則按照國家名稱的字母順列排列。以下程式要輸出的內容:
22. 7 檔案
世界各國教育支出比例排名 (三)
36
由以上的輸出規定,本範例在讀入資料檔後要依 GDP 支出百分比排序
,同時在列印時除了要改變資料排列格式外,也要微幅更改呈現資料,這樣
的簡單要求是試算表程式無法勝任的,通常透過程式設計才能處理。一般來
說,資料處理是 python 程式語言的強項,經常只要短短的幾十列程式就
能解決大多數問題。
以下的程式大致區分為兩部份,第一部份為讀檔,檔案的每一列包含國
名、GDP、年份、來源等等,仔細觀察資料,發現有些國家的名稱超過一個
字,此時可使用星號式子將國名先存為字串串列,之後在將其合併為單一字
串。程式的第二部份為排序,在 sorted 函式內定義排序標準,回傳排序
串列用來表示資料是先依 GDP 百分比由大到小,再依國名字母順序排列。
最後在程式末尾使用 format 重新排列資料後列印。
23. 7 檔案
世界各國教育支出比例排名 (四)
37
nations , gdps , years = [] , [] , []
with open("edu.dat") as infile :
for line in infile :
if line.isspace() : continue
# 星號將多字串的國家名稱儲存到串列
*nation , gdp , year , src = line.split()
# 儲存國名與年度資料於串列
nations.append( " ".join(nation) )
years.append( year )
# 沒有資料時,gdp 以 -1 替代
if year == "n.a." :
gdps.append( -1 )
else :
gdps.append( float(gdp) )
24. 7 檔案
世界各國教育支出比例排名 (五)
38
i = 1
# 依 gdp 由大到小,國名依字母順序排列
for nation , gdp , yr in sorted( zip(nations,gdps,years) ,
key=lambda p : ( -p[1] , p[0] ) ) :
if gdp == -1 :
line = "{:>3}:{:>5} [{:>4}] {:}".format( i , "---" ,
yr , nation )
else :
line = "{:>3}:{:>5.1F} [{:>4}] {:}".format( i , gdp ,
yr , nation )
print( line )
i += 1