--- tags: gps --- # 2022-GPS-Data-Skills-Course-Python f Course infomration in Canvasf Syllabus: https://ucsdlib.github.io/win2022-gps-python/ Software Installation: https://www.anaconda.com/products/individual ## Collaborative Notes: Please sign in here: Hong E g E E E E E E E E E E E E E E yaohong wang, yaw045@ucsd.edu qihan huang, q7huang@ucsd.edu Himanshu Pykurel, hpykurel@ucsd.edu yuting wan, y7wan@ucsd.edu Zizan Wang, ziw011@ucsd.edu Yilin Che, yiche@ji.edu Yizhuo Liu, yil118@ucsd.edu Dahlia Lopez del006@ucsd.edu ### First Name, last name, email Jaeyeon, Park, jap013@ucsd.edu Yunxin Liu, yul188@ucsd.edu Nikki Qi, haqi@ucsd.edu shivangi, gupta, shg011@ucsd.edu Himanshu, Pykurel, hpykurel@ucsd.edu Jiayi Hao, j2hao@ucsd.edu Hung-Yang (Jason), Chien hchien@ucsd.edu Reid Otsuji rotsuji@ucsd.edu Collin Boudreaux cboudreaux@ucsd.edu Erika Gastelum, edgastel@ucsd.edu Michael Berman miberman@ucsd.edu Stella Lin s3lin@ucsd.edu Wenjun Gong w7gong@ucsd.edu Troy Tuquero ttuquero@ucsd.edu Jasmine Moheb jmoheb@ucsd.edu Himanshu, Pykurel, hpykurel@ucsd.edu Yu Shi, yus064@ucsd.edu Stevinson, Tendon, stendon@ucsd.edu Hong En Jonas, Lim, helim@ucsd.edu Tirado, Tino, ttirado@ucsd.edu Mariya, Nikseresht, mniksere@ucsd.edu Woojong, Kim, w5kim@ucsd.edu Alayna, Bone, abone@ucsd.edu Salma Shaikh, sshaikh@ucsd.edu Morgan Cohen m7cohen@ucsd.edu PeterLLLLLLLLLLL Wilborn, pwilborn@ucsd.edu Anna Kraemer akraemer@ucsd.edu Emily Irion, eirion@ucsd.edu Chuyu, Liu, chl082@ucsd.edu Li Jiang,l6jiang@ucsd.edu Kwadwo Asiedu kasiedu@ucsd.edu Isai Hernandez i4hernandez@ucsd.edu Austin Brown aubrown@ucsd.edu Chengan, Li, chl030@ucsd.edu Nicholas Valle njvalle@ucsd.edu Lisa Howard, lmhoward@ucsd.edu TsuPing, Wang, tsw002@ucsd.edu Ziyuan Zhu, ziz063@ucsd.edu Yizhuo Liu, yil118@ucsd.edu | Column 1 | Column 2 | Column 3 | | -------- | -------- | -------- | | Text | Text | Text | Youhyun, Kang, y7kang@ucsd.edu Bonnie Devenney, bdevenne@ucsd.edu Adrian Rodriguez Valdez, adr057@ucsd.edu Sihan Chen, sic096@ucsd.edu Kevin Zhou, kezhou@ucsd.edu David Reimer, dreimer@ucsd.edu May Han, xuh042@ucsd.edu Rebecca Howard, r1howard@ucsd.edu Emily Davalos, edavalos@ucsd.edu Yuting Wan, y7wan@ucsd.edu Ernesto Castañeda, ecastaneda@ucsd.edu Dan-bee lee, dbl001@ucsd.edu Valentina Chanci Arrubla, vchanciarrubla@ucsd.edu Katy Norris, kenorris@ucsd.edu Meghan Mattioli, mazavala@ucsd.edu Zhibei Wang, zhw048@ucsd.edu Daniela, Hall Lagunes, dhalllag@ucsd.edu Nick Heimann, nheimann@ucsd.edu Poonam Narewatt, pnarewat@ucsd.edu Sam Cohen, szcohen@ucsd.edu Kelli, Maples, kmaples@ucsd.edu Vanessa, Ramos-Madrid, vramosma@ucsd.edu Hanya Jiang haj002@ucsd.edu Sora Park sop006@ucsd.edu Brrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr Sheerine Karamzadeh, skaramzadehrahimi@ucsd.edu Broderick Topil, btopil@ucsd.edu Sultan Alomari, salomari@ucsd.edu Yue Yu, yuy039@ucsd.edu yuting wan,y7wan@ucsd.edu Mackenna, Rawlins, mjrawlins@ucsd.edu Meiyu Su, m2su@ucsd.edu Jared Hernandez jah014@ucsd.edu Lisa Howard, lmhoward@ucsd.edu Zhengbo Zhang, zhz086@ucsd.edu Zizan Wang, ziw011@ucsd.edu Katie Simonian, ksimonian@ucsd.edu Patricia Resurreccion, paresurr@ucsd.edu Yuki Imura, yimura@ucsd.edu TungCheh(Maxwell)Chien tcchien@ucsd.edu Jeffrey, Myers, jmyers@ucsd.edu shivangi gupta, shg011@ucsd.edu Yelaine Wang yyw003@ucsd.edu John Kim jok015@ucsd Nicholas Valle njvalle@ucsd.edu Vorathip Plengpanit vplengpa@ucsd.edu Ziyuan Zhu, ziz063@ucsd.edu Chengan, Li, chl030@ucsd.edu Delana Du, ddu@ucsd.edu Sunny Xu, qixu@ucsd.edu Tomoyuki Aoki, taoki@ucsd.edu Kejun Chen, kec007@ucsd.edu Ayano Kano, akano@ucsd.edu Elisabeth Earley, eearley@ucsd.edu Tsu Ping Wang, tsw002@ucsd.edu Elizabeth Muthoni,emuthoni@ucsd.edu Yimeng Yang, yiy047@ucsd.edu Xinyi Du x8du@ucsd.edu Chuan Xu,chx072@ucsd.edu Haoran Jiang haj005@ucsd.edu Elise Spencer, Enspencer@ucsd.edu Juliane Alfen, jalfen@ucsd.edu Jo Kim, kfkim@ucsd.edu Chenhao Nie. cnie@ucsd.edu Bowen Deng b2deng@ucsd.edu Hyun Ji Jung, hjjung@ucsd.edu Hyejin Jung, h8jung@ucsd.edu Yishu Tang, yit013@ucsd.edu Sam Cohen, szcohen@ucsd.edu Shuting Wang, shw009@ucsd.edu Bing Rethy, brethy@ucsd Yilin, Che, yiche@ucsd.edu Jinwei XU jix002@ucsd.edu Jaeyeon,assssssssssssss Park, jap013@ucse.edu Mattioli, Meghan, mazavala@ucsd.edu Yizhuo Liu, yil118@ucsd.edu Poonam Narewatt, pnarewat@ucsd.edu Yixiao, Huang, yih041@ucsd.edu Haoran, Jiang haj005@ucsd.edu Hyejin Jung h8jung@ucsd.edu Elise Spencer, Enspencer@ucsd.edu Emerson Tsui(Xu), shx007@ucsd. Yuting Wan, y7wan@ucsd.edu # NOTES: Jupyterlab will be used for the lessons [m] Markdown cell = notes [#]also works in code cell for notes [b] = add cell below [a] is above [r]Raw cells cannot have text edits https://www.markdownguide.org/getting-started/ https://www.markdownguide.org/basic-syntax/ Python variable #assigned name for a value variable names are case sensitive print() #use to display the value anything with letters is a string and needs quotation marks use # to make code comments e.g. ```python car1 = 'Toyota' #this is a code comment ``` car1= 'Kia' car2= 'Honda' print(car2) Challenge: Assign the variable named color1 to the value red and color2 to the value blue and print - red is not blue. Write as code. color1='red' color2='blue' print(color1,'is not',color2) Variables can be used as caluculations ```python= age1 = 32 age2 = age1 + 3 print('age in three years:', age2) ``` calculations ```python= 12 * 23 * 450 ``` # Lecture 2 Please sign in Yaohong Wang yaw045@ucsd.edu first name, last name, email Hung-Yang, Chien, hchien@ucsd.edu Yizhuo Liu, yil118@ucsd.edu Chenhao Nie, cnie@ucsd.edu Emily Davalos, edavalos@ucsd.edu Jiayi Hao, j2hao@ucsd.edu Nikki Qi, haqi@ucsd.edu Bing Rethy, brethy@ucsd.edu Nick Heimann, nheimann@ucsd.edu Katie Simonian, ksimonian@ucsd.edu Erika Gastelum, edgastel@ucsd.edu Vorathip Plengpanit, vplengpa@ucsd.edu Morgan Cohen, m7cohen@ucsd.edu Maxwell Chien, tcchien@ucsd.edu Jared Hernandez, jah014@ucsd.edu Stella Lin, s3lin@ucsd.edu Salma Shaikh, sshaikh@ucsd.edu Zizan Wang, ziw011@ucsd.edu Sunny Xu, qixu@ucsd.edu Kwadwo Asiedu, kasiedu@ucsd.edu Jeffrey Myers, jmyers@ucsd.edu Wenjun Gong, w7gong@ucsd.edeu Peter J. Wilborn, pwilborn@ucsd.edu Tino Tirado, ttirado@ucsd.edu Sheerine Karamzadeh, skaramzadehrahimi@ucsd.edu Valentina Chanci Arrubla, vchanciarrubla@ucsd.edu Sora Park, sop006@ucsd.edu May Han, xuh042@ucsd.edu John Kim, jok015@ucsd.edu Yelaine Wang yyw003@ucsd.edu Dahlia Lopez del006 Chuyu Liu, chl082@ucsd.edu shivangi gupta, shg011@ucsd.edu YimengE Yang, yiy047@uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu Rebecca Howard, r1howard@ucsd.edu Ernesto Castañeda ecastaneda@ucsd.edu Bonnie Devenney, bdevenne@ucsd.edu AAnna Kraemer akraemer@ucsd.edu Troy Tuquero ttuquero@ucsd.edu Brenna Wayne bwayne@ucsd.edu Mariya Nikseresht, mniksere@ucsd.edu Collin Boudreaux, cboudreaux@ucsd Michael Berman, miberman@ucsd.edu Chengan, Li, chl030@ucsd.edu Yuki Imura, yimura@ucsd.edu Hanya Jiang, haj002@ucsd.edu Zhibei Wang, zhw048@ucsd.edu Kelli Maples, kmaples@ucsd.edu Adrian R. Valdez, adr057@ucsd.edu Yunxin Liu, yul188@ucsd.edu Alayna Bone abone@ucsd.edu Meiyu Su, m2su@ucsd.edu Hyun Ji Jung, hjjung@ucsd.edu Koo Fum Kim, kfkim@ucsd.edu Yu Shi, yus064@ucsd.edu Dan bee Lee, dbl001@ucsd.edu Bowen Deng b2deng@ucsd.edu Katy Norris kenorris@ucsd.edu Yue Yu yuy039@ucsd.edu Li Jiang, l6jiang@ucsd.edu Elizabeth Muthoni emuthoni@ucsd.edu Woojong, Kim, w5kim@ucsd.edu Isai Hernandez i4hernandez@ucsd.edu Austin Brown aubrown@ucsd.edu Delana Du, ddu@ucsd.edu Jaeyeon, Park, jap013@ucsd.edu Lisa Howard, lmhoward@ucsd.edu Yu, Li, yul193@ucsd.edu Tomoyuki Aoki, taoki@ucsd.edu Stevinson Tendon, stendon@ucsd.edu Patricia Resurreccion, paresurr@ucsd.edu Jinwei XU jix002@ucsd.edu Juliane Alfen jalfen@ucsd.edu Yishu Tang, yit013@ucsd.edu Nicholas Valle njvalle@ucsd.edu Qi Li, qil023@ucsd.edu Broderick Topil, btopil@ucsd.edu Emily Irion, eirion@ucsd.edu Ziyuan Zhu, ziz063@ucsd.edu Yixiao, Huang, yih041@ucsd.edu David Reimer, dreimer@ucsd.edu Elise Spencer, enspencer@ucsd.edu Rawlins, Mackenna, mjrawlins@ucsd.edu Xinyi Du ,x8du@ucsd.edu qihan huang, q7huang@ucsd.edu Yilin Che, yiche@ucsd.edu # Notes ### Datatypes 3 primary: strings,, and floating point Integers are whole numbers, do not have decimals Floating point numbers are real numbers - can use decmial points stings - sequence of characters that are immutable. meaning once it is created it cannot be changed. type() #native function in python that tells you what your value datatype is ```python= AString = '1' AnInteger = 1 AFloat = 1.0 type(AString) type(AnInteger) type(1) ``` ```python= print(type(AString), type(1), type(AFloat)) ``` ## Challenge: What type of values are the following: 3.4, car1, 2589, E234, 'car2'? Use the appropriate built-in function to find out the datatypes. Answer": ```python= car1 = 2017 print(type(3.4)) print(type(car1)) print(type(3589)) print(type('E234')) print(type('car2')) ``` ```python= num1 = 2 num2 = 5 num3 = 'two' num4 = 6.5 print(num1 * num2) print(num3 * num2) print(num2*num4) print(num3*num4) #will produce an error ``` ```python= # you can use the '+' and '*' operators on strings full_name = 'Ahmed' + ' ' + 'Walsh' print(full_name) ``` ```python= separator = '=' * 10 print(separator) ``` Challenge: What type of value (integer, floating point number, or character string) would you use to represent each of the following? Try to come up with more than one good answer for eachproblem. For example, in # 1, when would counting days with a floating point variable make moresense than using an integer? 1. Number of days since the start of the year. **integer** 2. Time elapsed from the start of the year until now in days. **float** 3. Serial number of a piece of lab equipment. **string or integer** 4. A lab specimen’s age **integer or string** (string if date/time is required) 5. Current population of a city. **integers for small populations and floating points for large - millions** 6. Average population of a city over time. **floating** ## Converting datatypes ```python= print(1 + '2') # integer + string will produce an error print(1 + int('2')) #convert datatype to an integer print(1 + int('2')) # convert string to int print(1 + float('2')) #convert datatype to an float ``` Challenge 3 - not covered in lecture Which of the following will return the floating point number 2.0? Note: there may be more thanone right answer. (Edit cell) first = 1.0 second = "1" third = "1.1" 1. first + float(second) 2. float(second) + float(third) 3. first + int(third) 4. first + int(float(third)) 5. int(first) + int(float(third)) 6. 2.0 * second ### you can mix integrs and floats in operations ```python print('half is', 1/2.0) ``` ### functions ```python= print('before') print() print('after') ``` # Please SIgn in here session 3 ### last name, first, name, email Park, Sora, sop006@ucsd.edu Gastelum, Erika, edgastel@ucsd.edu Yaohong Wang yaw045@ucsd.edu Anna Kraemer akraemer@ucsd.edu Daniela, Hall Lagunes, dhalllag@ucsd.edu Nick Heimann, nheimann@ucsd.edu Bone, Alayna, abone@ucsd.edu Chien, Maxwell, tcchien@ucsd.ed Maples, Kelli, kmaples@ucsd.edu Nikseresht, Mariya, mniksere@ucsd.edu TsuPing, Wang, tsw002@ucsd.edu Ziyuan Zhu, ziz063@ucsd.edu Wilborn, Peter, pwilborn@ucsd.edu u Rawlins, Mackenna, mjrawlins@ucsd.edu Haoran Jiang, haj005@ucsd.edu qihan huang, q7huang@ucsd.edu Hong En Jonas Lim, helim@ucsd.edu Bing Rethy, brethy@ucsd.edu shivangi gupta, shg011@ucsd.edu Yue Yu yuy039@ucsd.edu Myers, Jeffrey, jmyers@ucsd.edu Nikki Qi, haqi@ucsd.edu Jaeyeon, Park, jap01jap013@ucsd.edu Hung-Yang (Jason), Chien, hchien@ucsd.edu Chenhao Nie , cnie@ucsd.edu Moheb, Jasmine jmoheb@ucsd.edu Wenjun Gong, w7gong@ucsd.edu Simonian, Katie ksimonian@ucsd.edu Plengpanit, Vorathip vplengpa@ucsd.edu Adrian R. Valdez, Adr057@ucsd.edu David Reimer, dreimer@ucsd.edu Yuki Imura, yimura@ucsd.edu Tendon, Stevinson, stendon@ucsd.edu John Kim jok015@ucsd.eduohn Kim jok015@ucsd.eduohn Kim jok015@ucsd.eduohn Kim jok015@ucsd.eduohn Kim jok015@ucsd.eduohn Kim jok015@ucsd.eduohn Kim jok015@ucsd.eduohn Kim jok015@ucsd.edu Collin Boudreaux, cboudreaux@ucsd.edu Su, Meiyu, m2su@ucsd.edu Hanya Jiang haj002@ucsd.edu Yu Shi, yus064@ucsd.edu SSSSSSSSSSSSSSSSSSS Yimeng Yang, yiy047@ucsd.edu Nicholas Valle njvalle.edu Jared Hernandez, jah014@ucsd.edu Rebecca Howard, r1howard@ucsd.edu Ernesto Castaneda ecastaneda@ucsd.edu :)H Yu Li, yul193@ucsd.edu Yelaine Wang yyw003@ucsd.edu Woojong, Kim, w5kim@ucsd.edu Emily Davalos, edavalos@ucsd.edu Wang,Zhibei,zhw048@ucsd.edu Karamzadeh, Sheerine skaramzadehrahimi@ucsd.edu Shuting Wang, shw009@ucsd.edu Zhengbo Zhang, zhz086@ucsd.edu Sunny Xu, qixu@ucsd.edu Michael Berman, miberman@ucsd.edu Topil, Broderick, btopil@ucsd.edu Troy Tuquero ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu ttuquero@ucsd.edu Koo Fum Kim, kfkim@ucsd.edu Tomoyuki Aoki, taoki@ucsd.edu Tirado, Tino ttirado@ucsd.edu Yizhuo Liu, yil118@ucsd.edu Poonam Narewatt, pnarewat@ucsd.edu Valentina Chanci Arrubla, vchanciarrubla@ucsd.edu Bowen Deng b2deng@ucsd.edu JIayiIayiIayiIayiIayiIayiIayiIayiIayiIayiIayiIayiIayiIayiIayiIayiIayiIayiIayiIayi Yishu Tang, yit013@ucsd.edu Sam Cohen, szcohen@ucsd.edu Dan-bee Lee, dbl001@ucsd.edu Emily Irion, eirion@ucsd.edu Bonnie Devenney, bdevenne@ucsd.edu Han, May, xuh042@ucsd.edu Chengan, Li, chl030@ucsd.edu Howard, Lisa, lmhoward@ucsd.edu Chuyu Liu, chl082@ucsd.edu Kwadwo Asiedu, kasiedu@ucsd.edu Patricia Resurreccion, paresurr@ucsd.edu Emerson Tsui(Xu), shx007@ucsd.edu Xinyi Du ,x8du@ucsd.edu Elizabeth Muthoni, emuthoni@ucsd.edu Yilin Che, yiche@ucsd.edu Yixiao Huang, yih041@ucsd.edu Jung, Hyun Ji, hjjung@ucsd.edu Yunxin Liu, yul188@ucsd.edu Alfen, Juliane jalfen@ucsd.edu Shaikh, Salma, sshaikh@ucsd.edu Peter,Wilborn, pwilborn@ucsd.edu Qi Zizan Wang. ziw011@ucsd.edu Li, qil023@ucsd.edu Mattioli, Meghan mazavala@ucsd.edu jinwei Xu jix002@ucsd.edu Morgan Cohen, m7cohen@ucsd.edu # NOTES #is a function ```python= round() max() min() ``` ## Challenge 1 What character has the index number of 8 in the variable named 'some_words' below? some_words = 'This is my writing' answer: ```python= some_words = 'This is my writing' print(some_words[8]) ``` #Slicing ```python= atom_name = 'sodium' print(atom_name[0:3]) ``` # Challenge 2 What does the following program print? atom_name = 'carbon' print('atom_name[1:3] is', atom_name[1:3]) answer: ```python= atom_name = 'carbon' print('atom_name[1:3] is:', atom_name[1:3]) ``` The built-in function 'len' can use the variable name as well as the actual string to find the length. ```python= print(len(12345)) # error, len does not work on integers ``` convert the integer to a string and the use len() ```python= print(len(str(9834516123))) ``` ```python= atom_name1 = 'helium' print(len(atom_name1)) ``` # Challenge 3 Assign the variable _song_ to the value _Mary had a little lamb_. What is the length of the variable song? answer: ```python= song = 'Mary had a little lamb' print(len(song)) ``` help() #This function is used with other functions as a kind of dictionary. When used on another function, the output explains what that function does. *Note: If you input only 'help()', the output is an interface for searching not only functions but pretty much any Python syntax element. ## libraries A library is a collection of files (called modules) that contains functions for use by other programs. May also contain data values (e.g., numerical constants) and other things. Library’s contents are supposed to be related, but there’s no way to enforce that. The Python standard library (https://docs.python.org/3/library/) is an extensive suite of modules that comes with Python itself. # using the math library load library ```python= import math as #m is a pseudo name for the math library. once assigned you can use 'm' to call the library ``` ```python= print('cos(pi) is', math.cos(math.pi)) ``` # download data from Canvas inflammation_01.csv # tabular data When working with most of the libraries mentioned, we use datasets (which is a collection of data) that are usually presented in tabluar form. This is referred to as Tabular Data. ### make sure your datafile is in same folder as your jupyterLab notebook Import numpy library: ```python= import numpy as np ``` load data file: ```python= np.loadtxt(fname='inflammation-01.csv', delimiter = ',') ``` Assign dataset to variable: ```python= data = np.loadtxt(fname='inflammation-01.csv', delimiter = ',') ``` ```python= print(np.mean(data)) ``` # Session 4 01/13/2022 # Please SIgn in here session 3 # first name, last name, email Gastelum, Erika, edgastel@ucsd.edu Sam Cohen, szcohen@ucsd.edu Yaohong Wang, yaw045@ucsd.edu Sora Park, sop006@ucsd.edu Yizhuo Liu, yil118@ucsd.edu shg011@ucsd.edu Michael Berman, miberman@ucsd.edu Sunny Xu, qixu@ucsd.edu Nikki Qi, haqi@ucsd.edu Jasmine Moheb, jmoheb@ucsd.edu Lisa Howard, lmhoward@ucsd.edu Yunxin Liu, yul188@ucsd.edu Poonam Narewatt, pnarewat@ucsd.edu Emily Davalos, edavalos@ucsd.edu Chenhao Nie. cnie@ucsd.edu Tirado, Tino ttirado@ucsd.edu Bing Rethy, brethy@ucsd.edu WIlborn, Peter, pwilborn@ucsd.edu Adrian R. Valdez, adr057@ucsd.edu Ernesto Castaneda, ecastaneda@ucsd.edu Yuki Imura, yimura@ucsd.edu Salma Shaikh, sshaikh@ucsd.edu Jared Hernandez, jah014@ucsd.edu Nick Heimann, nheimann@ucsd.edu Wenjun Gong, w7gong@ucsd.edu Valentina Chanci Arrubla, vchanciarrubla@ucsd.edu Woojong, Kim, w5kim@ucsd.edu Stella Lin, s3lin@ucsd.edu Yu Shi, yus064@ucsd.edu Morgan Cohen, m7cohen@ucsd.edu Yu Li, yul193@ucsd.edu Haoran Jiang, haj005@ucsd.edu Hung-Yang (Jason), Chien, hchien@ucsd.edu Bonnie Devenney, bdevenne@ucsd.edu Patricia Resurreccion, paresurr@ucsd.edu Sheerine Karamzadeh, skaramzadehrahimi@ucsd.edu CollinMMMMMMMMMM Boudreaux, cboudreaux@ucsd.edu Yishu Tang, yit013@ucsd.edu Jeff, Myers, jmyers@ucsd.edu Yue Yu yuy039@ucsd.edu Jiayi Hao, j2hao@ucsd.edu Yelaine Wang yyw003@ucsd.edu Hanya Jiang, haj002@ucsd.edu Austin Brown, aubrown@ucsd.edu Alayna Bone, abone@ucsd.edu Katie Simonian ksimonian@ucsd.edu Emily Irion, eirion@ucsd.edu David Reimer, dreimer@ucsd.edu Qi Li, qil023@ucsd.edu Elizabeth Muthoni, emuthoni@uscd.edu Mariya Nikseresht, mniksere@ucsd.edu Shuting Wang, shw009@ucsd.edu Stevinson Tendon, stendon@ucsd.edu Elise Spencer, Enspencer@ucsd.edu Rawlins, Mackenna, mjrawlins@ucsd.edu maxwell chien, tcchien@ucsdedu Rebecca Howard, r1howard@ucsd.edu Zhengbo Zhang, zhz086@ucsd.edu Kwadwo Asiedu, kasiedu@@@ Hyun Ji Jung, hjjung@ucsd.edu Troy Tuquero ttuquero@ucsd.edu Plengpanit, Vorathip vplengpa@ucsd.edu Tomoyuki Aoki, taoki@ucsd.edu Chengan, Li, chl030@ucsd.edu Nicholas Valle, njvalle@ucsd.edu Kim, John, jok015@ucsd,edu Delana Du, ddu@ucsd.edu Broderick Topil, btopil@ucsd.edu Yimeng Yang, yiy047@ucsd.edu Hong En Jonas, helim@ucsd.edu Ziyuan Zhu,ziz063@ucsd.edu Jaeyeon, Park, jap013@ucsd.edu Xinyi Du,x8du@ucsd.edu Koo Fum Kim, kfkim@ucsd.edu Anna Kraemer akraemer@ucsd.edu Wang, Zhibei, zhw048@ucsd.edu Chuyu Liu, chl082@ucsd.edu Bowen Deng, b2deng@ucsd.edu Meghan Mattioli, mazavala@ucsd.edu Juliane Alfen, jalfen@ucsd.edu Meiyu, Su, m2su@ucsd.edu Dan Bee Lee, dbl001@ucsd.edu Zizan Wang, ziw011@ucsd.edu TsuPing, Wang, tsw002@ucsd.edu Kelli Maples, kmaples@ucsd.edu Qihan huang, q7huang@ucsd.edu Emerson Tsui, shx007@ucsd.edu Yilin Che, yiche@ucsd.edu Yixiao Huang, yih041@ucsd.edu # Pandas and plotting What is Pandas? it is a free software library written for the Python programming language for data manipulation and analysis. It one of the most commonly used libraries offering data structures and operations for manipulating diverse datasets including numerical tables and time series. ### importing pandas ```python= import pandas as pd ``` ```python= ``` ```python= print(data) ``` when loading data, make sure to check your file location and datafile name macos find path: cmd + option + p # Challenge 1 Read the data in 'gapminder_gdp_americas.csv' into a variable called 'americas' and display its summary statistics. set index to country. answer: ```python= americas = pd.read_csv('gapminder_gdp_americas.csv', index_col='country') print(americas) ``` ```python= data = pd.read_csv('gapminder_gdp_oceania.csv', index_col='country') ``` ```python= data = pd.read_csv('gapminder_gdp_oceania.csv', index_col='country') print(data) ``` view dataframe: ```python= data.info ``` ```python= print(data.T) ``` write to csv: ```python= data.to_csv('mydatafile.csv') ``` ```python= data = pd.read_csv('gapminder_gdp_europe.csv', index_col='country') data = pd.DataFrame(data) print(data.iloc[0, 0]) ``` # Python lesson 5 - 85 ## sign in first name, last name, email Sora, Park, sop006@ucsd.edu Erika, Gastelum, edgastel@ucsd.edu John Kim jok015@ucsd.edu Vorathip Plengpanit, vplengpa@ucsd.edu Hung-Yang (Jason), Chien, hchien@ucsd.edu hanya jiang, hhhhhhhhhhhhhhhhhhhhhhaj002@ Wilborn, Peter, pwilborn@ucsd.edu Stella Lin, s3lin@ucsd.edu Salma Shaikh, sshaikh@ucsd.edu Jared Hernandez, jah014@ucsd.edu Troy Tuquero ttuquero@ucsd.edu Jiayi Hao. j2hao@ucsd.edu Chuyu Liu, chl082@ucsd.edu Nicholas Valle njvalle@ucsd.edu May, Han, xuh042@ucsd.edu Collin Boudreaux, cboudreaux@ucsd.edu Sunny Xu, qixu@ucsd.edu Lisa Howard, lmhoward@ucsd.edu Hyun Ji Jung, hjjung@ucsd.edu Patricia Resurreccion, paresurr@ucsd.edu maxwell chien, tcchien@ucsd.edu Michael Berman, miberman@ucsd.edu Yuki Imura, yimura@ucsd.edu Alayna, Bone, abone@ucsd.edu Chenhao Nie. cnie@ucsd.edu Bonnie Devenney, bdevenne@ucsd.edu Mariya Nikseresht, mniksere@ucsd.edu Tirado, Tino, ttirado@ucsd.edu Broderick, Topil, btopil@ucsd.edu Emily Davalos, edavalos@ucsd.edu Zhibei, Wang, zhw048@ucsd.edu Yue Yu yuy039@ucsd.edu Yu Shi, yus064@ucsd.edu Simonian,Katie,ksimonian@ucsd.edu Shuting Wang, shw009@ucsd.edu Woojong, Kim, w5kim@ucsd.edu Rebecca Howard, r1howard@ucsd.eduShx Stevinson Tendon, stendon@ucsd.edu Yelaine Wang, yDDDDDDDDDDyw003@ucsd.edu ssssssssSam Cohen, szcohen@ucsd.edu Poonam Narewatt, pnarewat@ucsd.edu Nick Heimann, nheimann@ucsd.edu Jasmine Moheb, jmoheb@ucsd.edu Qi Li, qil023@ucsd.edu Nikki Qi, haqi@ucsd.edu Morgan Cohen, m7cohen@ucsd.edu Sheerine Karamzadeh, skaramzadehrahimi@ucsd.edu shg011@ucsd.edu Yu Li, yul193@ucsd.edu Tomoyuki Aoki, taoki@ucsd.edu Anna Kraemer akraemer@ucsd.edu Hong En Jonas helim@ucssd.edu Jeff Myers, jmyers@ucsd.edu Haoran Jiang,haj005@ucsd.edu Ziyuan Zhu,ziz063@ucsd.edu Yaohong Wang, yaw045@ucsd.edu Dan bee Lee, dbl001@ucsd.edu Ernesto Castaneda, ecastaneda@ucsd.edu Kwadwo Asiedu, kasiedu@ucsd.edu Meiyu Su, m2su@ucsd.edu Delana Du, ddu@ucsd.e austin brown, aubrown@ucsd.edu Juliane Alfen jalfen@ucsd.edu Dahlia Lopez del006@ucsd.edu Yishu Tang, yit013@ucsd.edu Yimeng Yang, yiy047@ucsd.edu Emily Irion, eirion@ucsd.edu Kelli Maples, kmaples@ucsd.edu Chengan, Li, chl030@ucsd.edu Wenjun Gong, w7gong@ucsd.edu Valentina Chanci Arrubla, vchanciarrubla@ucsd.edu David Reimer, dreimer@ucsd.edu Brenna Wayne, bwayne@ucsd.edu Meghan Mattioli, mazavala@ucsd.edu Rawlins, Mackenna, mjrawlins@ucsd.edu Elise Spencer, Enspencer@ucsd.edu Yizhuo Liu, yil118@ucsd.edu Yuting Wan, y7wan@ucsd.edu Koo Fum Kim, kfkim@ucsd.edu Bing Rethy, brethy@ucsd.edu Hyejin Jung, h8jung@ucsd.edu TsuPing, Wang, tsw002@ucsd.edu zizan wang,ziw011@ucsd.edu Juliane Alfen, jalfen@ucsd.edu Bowen deng b2deng.ucsd.edu jinwei XU jix002@ucsd.edu Yunxin Liu yul188@ucsd.edu ```python import matplotlib.pyplot as plt time = [0, 1, 2, 3] position = [0, 100, 200, 300] plt.plot(time, position) # (x,y) = (time, position) plt.xlabel('Time (hr)') plt.ylabel('Position (km)') #plt.text(0.5, 50, 'Some_text') ``` ```python import pandas as pd data = pd.read_csv('gapminder_gdp_oceania.csv', index_col='country') years = data.columns.str.strip('gdpPercap_') data.columns = years.astype(int) data.loc['Australia'].plot() ``` ## Loops: ```python= for number in [2,3,5]: print(number) ``` ```python= primes = [2,3,5] for p in primes: squared = p ** 2 cubed = p ** 3 print(p, squared, cubed) ``` ```python for number in range(0,3): print(number) for number in range(3): print(number) ``` ```python= total = 0 for number in range(1,11): total = total + number print(total) ``` ```python= total = 0 for number in range(1,11): print(total,number) total = total + number print(total) ``` ## conditionals ```python= mass = 3.54 if mass > 3.0: print(mass, 'is large') mass = 2.07 if mass > 3.0: print(mass, 'is large') ``` ```python= masses = [3.54, 2.07, 9.22, 1.86, 1.71] for m in masses: if m > 3.0: print(m, 'is large') ``` ```python= masses = [3.54, 2.07, 9.22, 1.86, 1.71] for m in masses: if m > 3.0: print(m, 'is large') else: print(m, 'is small') ``` ## challenge 1 What does this program print? *try to guess before running the code ```python pressure = 71.9 if pressure > 50.0: pressure = 25.0 elif pressure <= 50.0: pressure = 0.0 print(pressure) ``` ```python= velocity = 10.0 if velocity > 20.0: print('moving too fast') else: print('adjusting velocity') velocity = 50.0 ``` ```python= velocity = 10 for i in range(5): print(i, ':', velocity) if velocity > 20: print('moving to fast') velocity = velocity - 5 else: print('moving too slow') velocity = velocity + 10 ``` ```python= velocity = 10 for i in range(5): print(i, ':', velocity) if velocity > 20: print('moving to fast') velocity = velocity - 5 else: print('moving too slow') velocity = velocity + 10 print('final velocity:', velocity) ``` Simonian, Katie ksimonian@ucsd.edu # Python sesson 5 - 88 ## sign in here ## first name last name, email Erika, Gastelum, edgastel@ucsd.edu John Kim, jok015@ucsd.edu Troy Tuquero ttuquero''''''''@ucsd.edu Yizhuo Liu, yil118@ucsd.edu Vorathip Plengpanit, vplengpa@ucsd.edu Mariya Nikseresht, mniksere@ucsd.edu Sam Cohen, szcohen@ucsd.edu Bonnie Devenney, bdevenne@ucsd.edu Yuki Imura, yimura@ucsd.edu Chuyu Liu, chl082@ucsd.edu Broderick, Topil, btopil@ucsd.edu Jared Hernandez, jah014@ucsd.edu Wenjun Gong, w7gong@ucsd.edu Emily Davalos, edavalos@ucsd.edu Jeffrey Myers, jmyers@ucsd.edu Michael Berman, miberman@ucsd.edu Nicholas Valle njvalle@ucsd.edu Tino Tirado ttirado@ucsd.edu Rebecca Howard, r1howard@ucsd.edu Chenhao Nie. cnie@ucsd.edu Sunny Xu, qixu@ucsd.edu Collin Boudreaux cboudreaux@ucsd.edu Wilborn, Peter, pwilborn@ucsd.edu Stevinson Tendon, stendon@ucsd.edu Emily Irion, Eirion@ucsd.edu Sheerine Karamzadeh, skaramzadehrahimi@ucsd.edu Yu Shi, yus064@ucsd.edu Rawlins, Mackenna, mjrawlins@ucsd.edu Zhibei Wang, zhw048@ucsd.edu Alayna Bone, abone@ucsd.edu Bing Rethy, bingrethy@ucsd.edu Nick Heimann, nheimann@ucsd.edu Elizabeth Muthoni, emuthoni@ucsd.edu Salma Shaikh, sshaikh@ucsd.edu Yaohong Wang yaw045@ucsd.edu Hyun Ji Jung, hjjung@ucsd.edu Meiyu Su, m2su@ucsd.edu shivangi gupta, shg011@ucsd.edu Ziyuan Zhu, ziz063@ucsd.edu Woojong, Kim, w5kim@ucsd.edu Meghan Mattioli mazavala@ucsd.edu Yue Yu yuy039@ucsd.edu Jinwei Xu jix002 @ucsd.edu Austin Brown aubrown@ucsd.edu Anna Kraemer akraemer@ucsd.edu Juliane Alfen, jalfen@ucsd.edu Qi Li, qil023@ucsd.edu Adrian Rodriguez Valdez, adr057@ucsd.edu Yunxin Liu, yul188@ucsd.edu TsuPing, Wang, tsw002@ucsd.edu Bowen Deng b2deng@ucsd.edu # Python sesson 6 ## sign in here ## first name last name, email Erika, Gastelum, edgastel@ucsd.edu Brenna Wayne bwayne@ucsd.edu Dan Bee Lee, dbl001@ucsd.edu Hung-Yang (Jason), Chien, hchien@ucsd.edu May Han, xuh042@ucsd.edu Sora Park, sop006@ucsd.edu Kwadwo Asiedu, kasiedu@ucsd.edu Yishu Tang, yit013@ucsd.edu Ernesto Castaneda, ecastaneda@ucsd.edu Valentina Chanci Arrubla, vchanciarrubla@ucsd.edu Xinyi Du,x8du@ucsd.edu Elise Spencer, enspencer@ucsd.edu Emerson Tsui(Xu), shx007@ucsd.edu Patricia Resurreccion, paresurr@ucsd.edu Nikki Qi, haqi@ucsd.edu David Reimer, dreimer@ucsd.edu Poonam Narewatt, pnarewat@ucsd.edu Stella Lin, s3lin@ucsd.edu Yelaine Wang, yyw003@ucsd.edu Tomoyuki Aoki, taoki@ucsd.edu Jiayi Hao, j2hao@ucsd.edu Yu Li, yul193@ucsd.edu Chengan, Li, chl030@ucsd.edu Salma Shaikh, sshaikh@ucsd.edu Morgan Cohen, m7cohen@ucsd.edu Hyejin Jung, h8jung@ucsd.edu Zizan,Wang ziw011@ucsd.edu Hong En Jonas, helim@ucsd.edu Kelli Maples, kmaples@ucsd.edu Shuting Wang, shw009@ucsd.edu Hyun Ji Jung, hjjung@ucsd.edu Li Jiang, l6jiang@ucsd.edu Hanya Jiang, haj002@ucsd.edu Bowen Deng b2deng@ucsd.edu Sunny Xu, qixu@ucsd.edu Code: ### Lists ```python= pressure_1 = 1 pressure_2 = 2 ``` ```python= pressures = [1.1, 3.2, 5.5, 6.4, 1.5] print('pressures:', pressures) print('length: ', len(pressures)) print('0th item', pressures[0]) print('1st item', pressures[1]) ``` ```python= numbers = [1,2,3] print('numbers before append:', numbers) numbers.append(4) print('numbers after append:', numbers) ``` ```python= for filename in ['data/gapminder_gdp_africa.csv', 'data/gapminder_gdp_asia.csv']: #make sure to use your own file path data = pd.read_csv(filename, index_col='country') print(filename, data.min()) ``` ```python= import glob print('All csv files inside data directory:', glob.glob('*.csv')) #make sure to use your file path to the data files e.g. ('data/*.txt') print('All txt files inside data directory:', glob.glob('*.txt'))#make sure to use your file path to the data files e.g. ('data/*.txt') ``` ## Challenge 1 Which of these files is not matched by the expression: glob.glob('data/\*as*\.csv')? 1. data/gapminder_gdp_africa.csv 2. data/gapminder_gdp_americas.csv 3. data/gapminder_gdp_asia.csv ```python= for filename in glob.glob('gapminder_*.csv'): data = pd.read_csv(filename) print(filename, data['gdpPercap_1952'].min()) ``` # writing functions # Challenge 1 Without running this code, identify the location of any errors if there are any: ``` python= def another_function print("Syntax errors are annoying.") print("But at least python tells us about them!") print("So they are usually not too hard to fix.") ``` Solution: ```python= def another_function(): print("Syntax errors are annoying.") print("But at least Python tells us about them!") print("So they are usually not too hard to fix.") # ^Correct solution above. #1. We forgot to declare our parameters. #2. We forgot the colon following our parameters. #3. The middle line is indented too much. ``` ```python= def print_date(year, month, day): joined = str(year) + '/' + str(month) + '/' + str(day) print(joined) print_date(2022, 1, 2) ``` ```python= print_date(day = 2, year = 2022, month = 1) ``` ```python= def average(values): if len(values) == 0: return none return sum(values)/len(values) avg = average([1,3,4]) print(avg) ``` ```python= def print_date(year, month, day): joined = str(year) + '/' + str(month) + '/' + str(day) print(joined) print_date(1871, 3, 19) my_date = print_date(1871,2,19) print(my_date) ``` # Challenge 3 Now that we've fixed this function, print the result of the call. Why is this the result? ```python= def print_time(hour, minute, second): time_string = str(hour) + ':' + str(minute) + ':' + str(second) print(time_string) result = print_time(11, 37, 59) print('result of call is:', result) ```