Task 1: Basic Python ProgrammingBackgroundWe are going to use ‘PyCharm’, an integrated development environment (IDE) forPython. If you want to have it on your own devices, please follow the instructions onthe link: https://www.guru99.com/how-to-install-python.htmlInstall librariesWe need to install 3 Python data analysis libraries: pandas, matplotlib, plotnine, whichhelped us on data analysis and visualization. Please click: File-> Settings -> Project:data_lab -> Project interpreter, then click ‘+’ and type in the library you want to install.Even the first library is still being installed, you can type in the second and the thirdlibraries to install several packages in parallel. 2In the status bar, it shows ‘3 processes running’. You can click and see the installingprocess, which may take a few minutes.3Task 1.1: A number guess gameNow, we will use Python’s most common data types: integer, string, Boolean (True,False), list and dictionary; the most common logic structures: if-else and while; andthe most common operators: =, >, create an interesting guess game.https://www.dropbox.com/s/eh9puev65i5fk71/guess_num.py?dl=0a. Copy the codes, run and play.b. We need to introduce an access control mechanism to the game, as we only wantthe right person to play the game.We can add a simple user name & password check by the data type dictionary:passwordDictionary= {geb:2503, ray: ray110, cuhksz:666}Please check the code and play with the new feature.https://www.dropbox.com/s/2zqwoytcfyb5kkh/guess_num_access_control.py?dl=0Can you give a suggestion that how we can give the VIP pass “cuhksz” somefavor to make it easier for this account?c. We need to introduce a play-limit mechanism, as someone just got addicted to thegame. For example, the game should terminate if you played the game for more than3 times. Please screenshot your code implementation.d. Check with Google, explain what does the structure “try-except” do? Why weneed two? Do we really need two?4Task 2: Analyze Big DataTask 2.1: Load the dataWe are studying the species, hinder foot length and weight of animals captured bysensors. The data sets are stored in ‘surveys.csv’. Please download it and save it in thefolder of ‘data_lab’.https://www.dropbox.com/s/u9oi69xk6mmwe0f/surveys.csv?dl=0We will use the ‘read_csv’ function in the pandas library to load the file ‘surveys.csv’into a variable, then we can start to deal with the data stored in the variable. Download‘py_demo_part1.py’ and save it in the folder of ‘data_lab’.https://www.dropbox.com/s/6mphlaqde441lrc/py_demo_part1.py?dl=0a. Run the code, print (surveys_df)’ will print the variable that holds all data ofthe ‘surveys.csv’ file. The result excerpts the first and the last few lines of the file.b. Now we comment out ‘print (surveys_df)’, uncomment lProgramming代做、代寫Python程序設(shè)計(jì)舔稀、IDEine 5 & 6, and runthe code.‘print (surveys_df.dtypes)’ gets the type of each column:5‘print (type(surveys_df))’ gets the output:dtype: objectIt means the variable ‘surveys_df’ is an object of DataFrame of pandas. Bychecking the pandas documentation (https://pandas.pydata.org/pandasdocs/stable/reference/frame.html?highlight=dataframe),it says DataFrame is a “Twodimensionalsize-mutable, potentially heterogeneous tabular data structure”, whichmeans DataFrame is similar to a spreadsheet in Microsoft Excel.Note, you may face lots of attributes and functions on using a library (e.g.,pandas). If we compare a library to a person, attributes, are like this person’scharacteristics; while functions are like this person’s capability. Althoughprogrammers try their best to give attributes and functions nice names to let usersguess their functionalities at the first glance, the best way to find out what theyexactly mean or do is to check with Google or the documentation of that library (e.g.,the above link is the DataFrame page of the pandas documentation). It shows all theattributes and functions of DataFrame. For example, it includes the explanation of‘dtypes’, ‘head()’, ‘tail()’, and other functions in ‘py_demo_part1.py’. Pleaseuncomment and run the lines of functions you are interested in, and check with thedocumentation if you have any doubt.c. Find a proper indexing function in the documentation page to return the valueof the 3rd row, and the 8th column, which is 37.0. Note, the indexing of Python starts 6from 0. Please write the command down.d. What if I want to have the values of the first 3 rows, but only the columns from2nd to 4th, namely, the first 3 rows’ values of month, day and year. Please write thecommand down.e. What if I want to have all the values of the 6th column, namely, the species id.Please write the command down.f. What if I want to have all the values of the 6th column, but with the duplicatesremoved. Please write the command down.7Task 3: Visualize Big DataDownload ‘py_demo_part2.py’ and save it in the folder of ‘data_lab’.https://www.dropbox.com/s/32ozhbhaq7n11rg/py_demo_part2.py?dl=0a. Run the code, and use the documentation page to explore the plotninefunctions:https://plotnine.readthedocs.io/en/stable/b. Please use geom.point() to plot species_id vs hindfoot_length using sex asthe color parameter. In addition, please explain a bit what you observe from theplot.c. Please use geom.bar() to plot species_id vs weight using sex as the colorparameter. In addition, please explain a bit what you observe from the plot.d. Please use geom.point() to plot species_id vs hindfoot_length using sex asthe color parameter, but we want only years of 1979, 1993, 1999, 1977. Inaddition, please explain a bit what you observe from the plot.8END of Tutorial / lab-3轉(zhuǎn)自:http://www.6daixie.com/contents/3/4443.html
講解:Programming椎眯、Python挠将、IDE胳岂、PythonProlog|SQL
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門屎即,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人事富,你說(shuō)我怎么就攤上這事技俐。” “怎么了统台?”我有些...
- 文/不壞的土叔 我叫張陵雕擂,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我贱勃,道長(zhǎng)井赌,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任募寨,我火速辦了婚禮族展,結(jié)果婚禮上森缠,老公的妹妹穿的比我還像新娘拔鹰。我一直安慰自己,他們只是感情好贵涵,可當(dāng)我...
- 文/花漫 我一把揭開白布列肢。 她就那樣靜靜地躺著,像睡著了一般宾茂。 火紅的嫁衣襯著肌膚如雪瓷马。 梳的紋絲不亂的頭發(fā)上,一...
- 那天跨晴,我揣著相機(jī)與錄音欧聘,去河邊找鬼。 笑死端盆,一個(gè)胖子當(dāng)著我的面吹牛怀骤,可吹牛的內(nèi)容都是我干的费封。 我是一名探鬼主播,決...
- 文/蒼蘭香墨 我猛地睜開眼蒋伦,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼弓摘!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起痕届,我...
- 序言:老撾萬(wàn)榮一對(duì)情侶失蹤韧献,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后研叫,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體锤窑,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年嚷炉,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了果复。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布,位于F島的核電站忌栅,受9級(jí)特大地震影響车酣,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜索绪,卻給世界環(huán)境...
- 文/蒙蒙 一湖员、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧瑞驱,春花似錦娘摔、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至彤侍,卻和暖如春肠缨,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背盏阶。 一陣腳步聲響...
- 正文 我出身青樓脑慧,卻偏偏與公主長(zhǎng)得像惠窄,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子漾橙,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- **2014真題Directions:Read the following text. Choose the be...
- The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
- 對(duì)記者總是不太了解浙踢,只是在電視上,看見記者與主持人連線灿渴,站在街邊洛波,站在路口,站在事發(fā)現(xiàn)場(chǎng)骚露,急匆匆地交代情況之后便切...