{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": { "id": "L3b8d14C3hgL" }, "outputs": [], "source": [ "%%capture\n", "!pip install rpy2" ] }, { "cell_type": "code", "source": [ "import rpy2.robjects as ro\n", "from rpy2.robjects import r" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 58 }, "id": "rWd9DK6laeY4", "outputId": "f1bee0eb-7c5d-4590-9644-36f7206ec9a8" }, "execution_count": 3, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " [RTYPES.STRSXP]\n", "R classes: ('character',)\n", "['mundodes']" ], "text/html": [ "\n", " StrVector with 1 elements.\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
\n", " 'mundodes'\n", "
\n", " " ] }, "metadata": {}, "execution_count": 3 } ] }, { "cell_type": "code", "source": [ "# Load the RData file\n", "ro.r['load']('mundodes.RData')" ], "metadata": { "id": "J9lrib6ja130" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "print(r['ls']())" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "9aNW_MwXaiIf", "outputId": "54541e37-caa8-48ee-b361-493e77c17642" }, "execution_count": 4, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "[1] \"mundodes\"\n", "\n" ] } ] }, { "cell_type": "code", "source": [ "# Extract the R object 'mundodes'\n", "mundodes = ro.r['mundodes']\n", "\n", "# Write the R object to a CSV file with row names\n", "ro.r('write.csv(mundodes, \"mundodes.csv\", row.names=TRUE)')" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "wwgCkxodaicd", "outputId": "ce1af668-b677-4d31-d2f7-3c10088750a4" }, "execution_count": 5, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " [RTYPES.NILSXP]" ] }, "metadata": {}, "execution_count": 5 } ] }, { "cell_type": "code", "source": [ "print(mundodes)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "Qup9ELQF4PE5", "outputId": "2a782a78-b04d-44c9-a330-d051e7e216bb" }, "execution_count": 7, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ " nat mort mort_inf esp_homb esp_muj pnb\n", "Albania 24.7 5.7 30.8 69.6 75.5 600\n", "Bulgaria 12.5 11.9 14.4 68.3 74.7 2250\n", "Checos 13.4 11.7 11.3 71.8 77.7 2980\n", "Hungria 11.6 13.4 14.8 65.4 73.8 2780\n", "Polonia 14.3 10.2 16.0 67.2 75.7 1690\n", "Rumania 13.6 10.7 26.9 66.5 72.4 1640\n", "URSS 17.7 10.0 23.0 64.6 74.0 2242\n", "Bielorrusia 15.2 9.5 13.1 66.4 75.9 1880\n", "Ucrania 13.4 11.6 13.0 66.4 74.8 1320\n", "Argentina 20.7 8.4 25.7 65.5 72.7 2370\n", "Bolivia 46.6 18.0 111.0 51.0 55.4 630\n", "Brasil 28.6 7.9 63.0 62.3 67.6 2680\n", "Chile 23.4 5.8 17.1 68.1 75.1 1940\n", "Colombia 27.4 6.1 40.0 63.4 69.2 1260\n", "Ecuador 32.9 7.4 63.0 63.4 67.6 980\n", "Guayana 28.3 7.3 56.0 60.4 66.1 330\n", "Paraguay 34.8 6.6 42.0 64.4 68.5 1110\n", "Per\\xfa 32.9 8.3 109.9 56.8 66.5 1160\n", "Uruguay 18.0 9.6 21.9 68.4 74.9 2560\n", "Venezuela 27.5 4.4 23.3 66.7 72.8 2560\n", "Mexico 29.0 23.2 43.0 62.1 66.0 2490\n", "B\\xe9lgica 12.0 10.6 7.9 70.0 76.8 15540\n", "Finlandia 13.2 10.1 5.8 70.7 78.7 26040\n", "Dinamarca 12.4 11.9 7.5 71.8 77.7 22080\n", "Francia 13.6 9.4 7.4 72.3 80.5 19490\n", "Alemania 11.4 11.2 7.4 71.8 78.4 22320\n", "Grecia 10.1 9.2 11.0 65.4 74.0 5990\n", "Irlanda 15.1 9.1 7.5 71.0 76.7 9550\n", "Italia 9.7 9.1 8.8 72.0 78.6 16830\n", "Paises Bajos 13.2 8.6 7.1 73.3 79.9 17320\n", "Noruega 14.3 10.7 7.8 67.2 75.7 23120\n", "Portugal 11.9 9.5 13.1 66.5 72.4 7600\n", "Espa\\xf1a 10.7 8.2 8.1 72.5 78.6 11020\n", "Suecia 14.5 11.1 5.6 74.2 80.0 23660\n", "Suiza 12.5 9.5 7.1 73.9 80.0 34064\n", "Reino Unido 13.6 11.5 8.4 72.2 77.9 16100\n", "Austria 14.9 7.4 8.0 73.3 79.6 17000\n", "Japon 9.9 6.7 4.5 75.9 81.8 25430\n", "Canada 14.5 7.3 7.2 73.0 79.8 20470\n", "EEUU 16.7 8.1 9.1 71.5 78.3 21790\n", "Afganistan 40.4 18.7 181.6 41.0 42.0 168\n", "Bahrein 28.4 3.8 16.0 66.8 69.4 6340\n", "Iran 42.5 11.5 108.1 55.8 55.0 2490\n", "Irak 42.6 7.8 69.0 63.0 64.8 3020\n", "Israel 22.3 6.3 9.7 73.9 77.4 10920\n", "Jordania 38.9 6.4 44.0 64.2 67.8 1240\n", "Kuwait 26.8 2.2 15.6 71.2 75.4 16150\n", "Oman 45.6 7.8 40.0 62.2 65.8 5220\n", "Arabia Saudi 42.1 7.6 71.0 61.7 65.2 7050\n", "Turkia 29.2 8.4 76.0 62.5 65.8 1630\n", "Emiratos Arabes 22.8 3.8 26.0 68.6 72.9 19860\n", "Bangladesh 42.2 15.5 119.0 56.9 56.0 210\n", "China 21.2 6.7 32.0 68.0 70.9 380\n", "Hong Kong 11.7 4.9 6.1 74.3 80.1 14210\n", "India 30.5 10.2 91.0 52.5 52.1 350\n", "Indonesia 28.6 9.4 75.0 58.5 62.0 570\n", "Malasia 31.6 5.6 24.0 67.5 71.6 2320\n", "Mongolia 36.1 8.8 68.0 60.0 62.5 110\n", "Nepal 39.6 14.8 128.0 50.9 48.1 170\n", "Pakistan 30.3 8.1 107.7 59.0 59.2 380\n", "Filipinas 33.2 7.7 45.0 62.5 66.1 730\n", "Singapur 17.8 5.2 7.5 68.7 74.0 11160\n", "Srilanka 21.3 6.2 19.4 67.8 71.7 470\n", "Tailandia 22.3 7.7 28.0 63.8 68.9 1420\n", "Argelia 35.5 8.3 74.0 61.6 63.3 2060\n", "Angola 47.2 20.2 137.0 42.9 46.1 610\n", "Botswana 48.5 11.6 67.0 52.3 59.7 2040\n", "Congo 46.1 14.6 73.0 50.1 55.3 1010\n", "Egipto 38.8 9.5 49.4 57.8 60.3 600\n", "Etiopia 48.6 20.7 137.0 42.4 45.6 120\n", "Gabon 39.4 16.8 103.0 49.9 53.2 390\n", "Gambia 47.4 21.4 143.0 41.4 44.6 260\n", "Ghana 44.4 13.1 90.0 52.2 55.8 390\n", "Kenya 47.0 11.3 72.0 56.5 60.5 370\n", "Libia 44.0 9.4 82.0 59.1 62.6 5310\n", "Malawi 48.3 25.0 130.0 38.1 41.2 200\n", "Marruecos 35.5 9.8 82.0 59.1 62.5 960\n", "Mozambique 45.0 18.5 141.0 44.9 48.1 80\n", "Namibia 44.0 12.1 135.0 55.0 57.5 1030\n", "Nigeria 48.5 15.6 105.0 48.8 52.2 360\n", "Sierra Leona 48.2 23.4 154.0 39.4 42.6 240\n", "Somalia 50.1 20.2 132.0 43.4 46.6 120\n", "Surafrica 32.1 9.9 72.0 57.5 63.5 2530\n", "Sudan 44.6 15.8 108.0 48.6 51.0 480\n", "Swaziland 46.8 12.5 118.0 42.9 49.5 810\n", "Tunez 31.1 7.3 52.0 64.9 66.4 1440\n", "Uganda 52.2 15.6 103.0 49.9 52.7 220\n", "Tanzania 50.5 14.0 106.0 51.3 54.7 110\n", "Zaire 45.6 14.2 83.0 50.3 53.7 220\n", "Zambia 51.1 13.7 80.0 50.4 52.5 420\n", "Zimbabwe 41.7 10.3 66.0 56.5 60.1 640\n", "\n" ] } ] }, { "cell_type": "code", "source": [ "!head -n24 mundodes.csv | tail -n8" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "A-1bXCQcbDLU", "outputId": "695b8bc5-4685-4d9e-f701-7f07a1fa7a2a" }, "execution_count": 22, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\"Guayana\",28.3,7.3,56,60.4,66.1,330\n", "\"Paraguay\",34.8,6.6,42,64.4,68.5,1110\n", "\"Per�\",32.9,8.3,109.9,56.8,66.5,1160\n", "\"Uruguay\",18,9.6,21.9,68.4,74.9,2560\n", "\"Venezuela\",27.5,4.4,23.3,66.7,72.8,2560\n", "\"Mexico\",29,23.2,43,62.1,66,2490\n", "\"B�lgica\",12,10.6,7.9,70,76.8,15540\n", "\"Finlandia\",13.2,10.1,5.8,70.7,78.7,26040\n" ] } ] }, { "cell_type": "code", "source": [ "import pandas as pd" ], "metadata": { "id": "4ICV-d2Ma9x2" }, "execution_count": 6, "outputs": [] }, { "cell_type": "code", "source": [ "df = pd.read_csv('mundodes.csv', encoding='latin-1', index_col=0)\n" ], "metadata": { "id": "aR8TGKfVd87U" }, "execution_count": 28, "outputs": [] }, { "cell_type": "code", "source": [ "df.head(19)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 645 }, "id": "FWZrII2YeDqG", "outputId": "c40caa11-1d34-4c08-a926-38acef5b5dae" }, "execution_count": 29, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " nat mort mort_inf esp_homb esp_muj pnb\n", "Albania 24.7 5.7 30.8 69.6 75.5 600\n", "Bulgaria 12.5 11.9 14.4 68.3 74.7 2250\n", "Checos 13.4 11.7 11.3 71.8 77.7 2980\n", "Hungria 11.6 13.4 14.8 65.4 73.8 2780\n", "Polonia 14.3 10.2 16.0 67.2 75.7 1690\n", "Rumania 13.6 10.7 26.9 66.5 72.4 1640\n", "URSS 17.7 10.0 23.0 64.6 74.0 2242\n", "Bielorrusia 15.2 9.5 13.1 66.4 75.9 1880\n", "Ucrania 13.4 11.6 13.0 66.4 74.8 1320\n", "Argentina 20.7 8.4 25.7 65.5 72.7 2370\n", "Bolivia 46.6 18.0 111.0 51.0 55.4 630\n", "Brasil 28.6 7.9 63.0 62.3 67.6 2680\n", "Chile 23.4 5.8 17.1 68.1 75.1 1940\n", "Colombia 27.4 6.1 40.0 63.4 69.2 1260\n", "Ecuador 32.9 7.4 63.0 63.4 67.6 980\n", "Guayana 28.3 7.3 56.0 60.4 66.1 330\n", "Paraguay 34.8 6.6 42.0 64.4 68.5 1110\n", "Perú 32.9 8.3 109.9 56.8 66.5 1160\n", "Uruguay 18.0 9.6 21.9 68.4 74.9 2560" ], "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
natmortmort_infesp_hombesp_mujpnb
Albania24.75.730.869.675.5600
Bulgaria12.511.914.468.374.72250
Checos13.411.711.371.877.72980
Hungria11.613.414.865.473.82780
Polonia14.310.216.067.275.71690
Rumania13.610.726.966.572.41640
URSS17.710.023.064.674.02242
Bielorrusia15.29.513.166.475.91880
Ucrania13.411.613.066.474.81320
Argentina20.78.425.765.572.72370
Bolivia46.618.0111.051.055.4630
Brasil28.67.963.062.367.62680
Chile23.45.817.168.175.11940
Colombia27.46.140.063.469.21260
Ecuador32.97.463.063.467.6980
Guayana28.37.356.060.466.1330
Paraguay34.86.642.064.468.51110
Perú32.98.3109.956.866.51160
Uruguay18.09.621.968.474.92560
\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", "\n", "\n", "\n", " \n", "
\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "variable_name": "df", "summary": "{\n \"name\": \"df\",\n \"rows\": 91,\n \"fields\": [\n {\n \"column\": \"nat\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 13.699123079159962,\n \"min\": 9.7,\n \"max\": 52.2,\n \"num_unique_values\": 77,\n \"samples\": [\n 14.3,\n 42.6,\n 28.6\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"mort\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 4.683807088261518,\n \"min\": 2.2,\n \"max\": 25.0,\n \"num_unique_values\": 68,\n \"samples\": [\n 5.2,\n 6.6,\n 10.2\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"mort_inf\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 46.302322744923835,\n \"min\": 4.5,\n \"max\": 181.6,\n \"num_unique_values\": 79,\n \"samples\": [\n 8.4,\n 30.8,\n 7.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"esp_homb\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 9.727691425203641,\n \"min\": 38.1,\n \"max\": 75.9,\n \"num_unique_values\": 77,\n \"samples\": [\n 67.2,\n 63.0,\n 62.3\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"esp_muj\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 11.130675254625462,\n \"min\": 41.2,\n \"max\": 81.8,\n \"num_unique_values\": 79,\n \"samples\": [\n 81.8,\n 75.5,\n 80.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"pnb\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 8093,\n \"min\": 80,\n \"max\": 34064,\n \"num_unique_values\": 83,\n \"samples\": [\n 7600,\n 600,\n 22080\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 29 } ] }, { "cell_type": "code", "source": [ "df.loc[\"Albania\"]\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 272 }, "id": "ls797ClkeJgI", "outputId": "1b07b3d1-4e4d-4090-f19c-e09e890ed233" }, "execution_count": 31, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "nat 24.7\n", "mort 5.7\n", "mort_inf 30.8\n", "esp_homb 69.6\n", "esp_muj 75.5\n", "pnb 600.0\n", "Name: Albania, dtype: float64" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Albania
nat24.7
mort5.7
mort_inf30.8
esp_homb69.6
esp_muj75.5
pnb600.0
\n", "

" ] }, "metadata": {}, "execution_count": 31 } ] }, { "cell_type": "code", "source": [ "df.loc[\"Perú\"]" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 272 }, "id": "iui1kkYXeQCM", "outputId": "adf97279-06c9-4612-ce7b-52b43e8d4168" }, "execution_count": 32, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "nat 32.9\n", "mort 8.3\n", "mort_inf 109.9\n", "esp_homb 56.8\n", "esp_muj 66.5\n", "pnb 1160.0\n", "Name: Perú, dtype: float64" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Perú
nat32.9
mort8.3
mort_inf109.9
esp_homb56.8
esp_muj66.5
pnb1160.0
\n", "

" ] }, "metadata": {}, "execution_count": 32 } ] } ] }