Agroalimentary (2 points) ========================= From the Catalan Government web we have downloaded the file :download:`agroalimentary.csv` related to Catalan agroalimentary companies, that you already know. We have extended it with a randomly generated column named ``Facturacio`` showing the company billing in thousands of euros (:py:class:`int`). Download and study this file. We have already created a :py:ref:`DataFrame ` with this data. The following example shows the names of all the columns of this :py:ref:`DataFrame `, then a subdataframe example with columns corresponding to the company name (``Establiment``), the region (``Comarca``), the company type (``Titularitat``) and the billing (``Facturacio``), and, below, the same subdataframe with columns ``Establiment`` and ``Sector``: .. literalinclude:: test-agro.txt :language: python :lines: 4-31 Save the two following functions to file ``agro.py``. #. Write function :py:func:`agro1` that takes a :py:ref:`DataFrame ` as that described, a sector (:py:class:`str`) and a company type (:py:class:`str`). This function returns a tuple with a :py:ref:`DataFrame ` and an integer (:py:class:`int`). The returned :py:ref:`DataFrame ` is a subdataframe of the given one, with only those rows that correspond to the given sector and company type and the two columns ``'Establiment'`` and ``'Facturacio'``. This subdataframe is sorted by the column ``'Facturacio'`` in descending order. The returned integer is the total billing (column ``'Facturacio'``) of the computed subdataframe (1 point). Examples: .. literalinclude:: test-agro1.txt :language: python :lines: 6 - 21 .. note:: You have more tests in file :download:`test-agro1.txt` .. hint:: Use selection, methods ``sort_values`` and ``sum``. #. Write function :py:func:`agro2` that takes a :py:ref:`DataFrame `, as that described and two latitude values, :math:`la1` and :math:`la2` (:py:class:`float`), such that :math:`la1` in which the index is the sector (:py:class:`str`) and the value is the billing mean of the companies of this sector (:py:class:`float`), for the given latitudes inteval (1 point). Examples: .. literalinclude:: test-agro2.txt :language: python :lines: 6-16 .. note:: You have more tests in file :download:`test-agro2.txt` .. hint:: Use selection and methods ``groupby`` and ``mean``. .. note:: To run your functions you don't actually need to read the given data file. But you need to download and save it into your working folder because the given testfiles read from it to create the :py:ref:`DataFrame `.