讲解:Programming、Python、IDE、PythonProlog|SQL

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程序设计、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转自:http://www.6daixie.com/contents/3/4443.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,039评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,223评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,916评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,009评论 1 291
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,030评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,011评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,934评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,754评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,202评论 1 309
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,433评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,590评论 1 346
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,321评论 5 342
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,917评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,568评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,738评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,583评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,482评论 2 352

推荐阅读更多精彩内容