Skip to content

Commit

Permalink
#
Browse files Browse the repository at this point in the history
  • Loading branch information
anzonyquispe committed Jul 20, 2024
1 parent 11e24cd commit 881c89e
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
222 changes: 222 additions & 0 deletions Lecture_2/Assignment_2/Assignment_2 .ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1 Assignment\n",
"\n",
"It is totally prohibited to use any kind of loop. You can use stackoverflow. If you copy codes from previous answers, explain each step. No explanation is `0 points`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1.1 Tuple\n",
"\n",
"\n",
"\n",
"1. Print the first item of the second item of `tuple1` object. **Hint: Use indexing**<br><br>\n",
"2. Print the last item of the `tuple1` object.**Hint: Use indexing**<br><br>\n",
"3. Change the value \"orange\" for \"pink grapefruit\". Comment the output. **Hint: Is it possible?** <br><br>\n",
"4. Print the length of `tuple1`. **Hint: Length function**<br><br>\n",
"5. Sum all the elements of tuple2 and describe your steps and explain each of them. **Hint: Use `map` function.**<br><br>\n",
"6. Generate a new tuple object named as `tuple3` with the half values of `tuple2`. This tuple should be similar as `tuple2`, tuple of lists. **Hint: Use `map` funciont.**<br><br>"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"tuple1 = (\"Orange\", [10, 20, 30], (5, 15, 25))\n",
"tuple2 = ([7, 8], [9, 1], [10, 7])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1.2 Lists\n",
"1. Show the indices of the `np.nan` values in the `f_list` list. We want to see this output: `The indices 0, 1, 4, 7 have np.nan values.` **Hint: Use print function and [f-strings](https://realpython.com/python-f-strings/) to insert the indices values.**<br><br>\n",
"\n",
"2. Replicate 4 times the values of the list `p2_list`. We expect an ouput like this: `[ 2 , 3, 4, 5, 2 , 3, 4, 5, 2 , 3, 4, 5, 2 , 3, 4, 5]`. **Hint: Use multiplication function in `lists`and see the output.**<br><br>\n",
"3. Print the length of `f_list`. **Hint: Length function**<br><br>\n",
"4. Print `My teacher assistant is so boring.` using `text1` list. **Hint: Use the [`join` function](https://stackoverflow.com/questions/493819/why-is-it-string-joinlist-instead-of-list-joinstring)**<br><br>\n",
"5. Print `My TA is so boring, but is very funny.` using `text1` list.**Hint: Use the `join` function, and `extend` method.**<br><br>\n",
"6. Print <br>\n",
"`The max value of values1 is 86 and is located in the 0 index. ` <br>\n",
"`The min value of values1 is 0 and is located in the 7 index. ` <br> **Hint: Use the `f-string`, `min`, and `max` functions.**\n",
"<br>\n",
"7. Get two lists: `names` and `last_names` using `last_and_name` list. **Hint: Use `map` and `split`.**\n",
"<br>\n",
"8. Give only the last names of students who do not have email. Use the `emails` and `last_names` listt. **Hint: Use `map` and `split`.**\n",
"<br>"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"f_list = [np.nan , np.nan, \"Austria\", \"Germany\", np.nan, \"Pakistan\", \"np.nan\", np.nan ]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"text1 = ['My', 'teacher', 'assistant', 'is', 'so', 'boring.']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"p2_list = [ 2 , 3, 4, 5 ]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"values1 = [ 86, 86, 85, 85, 85, 83, 23, 0, 84, 1 ] "
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"52"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# These two lists a\n",
"last_and_name = [ \"CORNEJO SANCHEZ, CHRISTIAN SANTOS\", \"ORELLANA QUISPE, CRISTIAN NASSER\", \"MORALES CHOQUEHUANCA, ANGELICA KARINA\", \"GUIMARAY RIBEYRO, JOSE ROBERTO\", \"CAMACHO GAVIDIA, ABEL FERNANDO\", \"TINTAYA ORIHUELA, MEIR ALVARO\", \"CHAVEZ MARTINEZ, JOSELIN ALEXANDRA\", \"FIGUEROA MURO, LEONEL ARTURO\", \"GOMEZ CRIBILLERO, JOSE FELIPE\", \"PALOMINO SEGUÍN, AFRANIA\", \"LUZON CUEVA, BIANCA MARIETTE\", \"SUAÑA ZEGARRA, ADRIAN ANDRE\", \"SOTO POMACHAGUA, DORKAS YOMIRA JHERMY\", \"FIORENTINO MARTINEZ, LADY ALY\", \"LAMA MAVILA, HECTOR ANDRE\", \"MEZA HINOJO, GUSTAVO\", \"LOZADA MURILLO, PERSEO MARCELO\", \"ZAMBRANO JIMENEZ, MIGUEL ALONZO\", \"JACOBS LUQUE, NICOLAS\", \"VIDAL VIDAL, ROCIO GABRIELA\", \"TORRES ANICAMA, JANE CAMILA\", \"LOPEZ ESTRADA, MARIA ELISA\", \"BOYCO ORAMS, ALEJANDRO\", \"DIAZ BERROSPI, KARLINE ROSMELI\", \"RIEGA ESCALANTE, STEPHY ROSARIO\", \"LEVANO TORRES, VALERIA CECILIA\", \"ESQUIVES BRAVO, SEBASTIAN RENATO\", \"PEREZ GONZALES, JUAN CARLOS\", \"OTERO MAGUIÑA, MARIANA\", \"CLAVO CAMPOS, ANDREA BRIZETH\", \"AGUILAR GARCIA, ERICK JOSUE\", \"CALDAS VELASQUEZ, JOSUE DANIEL\", \"SALAS NUÑEZ BORJA, FABIO MANUEL\", \"PIZARRO VILLANES, FERNANDA NICOLLE\", \"QUILLATUPA MORALES, ANGELA ADELINA\", \"HUANCAYA IDONE, CESAR DANTE\", \"CALVO PORTOCARRERO, GABRIELA ISABEL\", \"IBAÑEZ ABANTO, ANGEL MAURICIO\", \"MELÉNDEZ APONTE, JUAN DIEGO\", \"CRISTIAN SERRANO, ARONE\", \"HINOJOSA CAHUANA, PERCY ALBERTH\", \"ANGLAS GARCÍA, KEVIN ARTURO\", \"ALDAVE ACOSTA, CESAR ERNESTO\", \"NÚÑEZ HUAMÁN, CÉSAR AGUSTO\", \"OBREGON HUAMAN, DIANA EDITH\", \"SOTO PACHERRES, RODRIGO FRANCO\", \"INGARUCA RIVERA, GRETTEL ALEXANDRA\", \"ROJAS HUAMAN, ROSA ANGELA\", \"NEYRA SALAS, DANTE OMAR\", \"HUERTA ESPINOZA, YAJAIRA ALEXANDRA\", \"HUANCA MARTINEZ, JORGE ALBERTO\", \"FLORES CADILLO, ALEXIS\" ]\n",
"emails = [\"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"\", \"\", \"\", \"\", \"\", \"[email protected]\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"[email protected]\", ]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1.3 Strings\n",
"\n",
"\n",
"1. Drop the duplicated blank spaces in `str1`. Do not use the regular expresions. Do not use the code shown in class. Explain your steps.**Hint: Use `split` method and `join` function.**\n",
"\n",
"2. Get the number of letters in the string .**Hint: Use `len`function.**\n",
"\n",
"3. Get the number of blank spaces (all of them) in the string .**Hint: Use `len`function.**\n",
"\n",
"4. Get the position of `@` in each string in the emails list. **Hint: Use `map`function and `find` method.**\n",
"\n",
"5. Identifies if exists `.edu.` in each string in the `emails` list. Get a list of Booleans. **Hint: Use `map`function and `find` method.**\n",
"\n",
"6. Get all the strings before the first dot `.`in each string in the `emails` list. Identifies how many of them has `@`. **Hint: Use `map`function and `find` method.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"str1 = 'I am too old'"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"emails = [\"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1.4 Pandas"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Import this dataset new_up_data_sysdif_block_lvl_ver2.csv located in the `_data` folder.\n",
"2. Import this dataset ESA_CLIMATE_CHANGE_tree_layers.csv located in the `_data` folder.\n",
"3. Merge both datasets using the key variables `pc11_s_id`,\t`pc11_d_id,`\t`pc11_sd_id`, `year`. \n",
"4. Generate a descriptive statistics for `per_TREES-BD`, `per_TREES-BE`, `per_TREES-ND`, `per_TREES-NE`.\n",
"5. Sum these 4 columns and name the new column as `sum_tree` and get a histogram.\n",
"6. Generate the histogram of these 4 columns `per_TREES-BD`, `per_TREES-BE`, `per_TREES-ND`, `per_TREES-NE` for the above and below median of the sum_tree variable.\n",
"\n",
"Do not forget to use relative paths."
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit 881c89e

Please sign in to comment.