{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "1. Read a file from a csv file stored in your computer.\n", "\n", "`import csv\n", "reader = csv.reader(open('filename.csv', 'r'))`\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import csv\n", "reader = csv.reader(open('filename.csv', 'r'))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Create a list of rows. \n", "\n", "When iterating the object reader, it converts each row into a list\n", "\n", "`???\n", "for rowList in reader:\n", " ????\n", "print (listA)`\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3. The result is similar to `[['joao', '22'], ['maria', '21'], ['manuela', '23'], ['antonio', '22']]`. So you have to convert the age from strings to integers or floats. If you use the function len it will gives you the number of rows." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "4. What is the average age of the students of the list?" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "22.0" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "5. What is the age of the older student?" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "23" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "6. Who is the older student? (suppose that ther is only on)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'manuela'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }