-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopy of Editable tema 7 PANDAS
1 lines (1 loc) · 67.8 KB
/
Copy of Editable tema 7 PANDAS
1
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[{"file_id":"1AbPMKfVKP-rh56r5xADSdPBUHoiA6MTv","timestamp":1687215800558},{"file_id":"1pBSlz__bNq2PPaBlz2s2ZvJSS89lva75","timestamp":1687148417529},{"file_id":"1V_PjI5CrJgOTtMGNdFsmmhjEHba9KHVb","timestamp":1687142568450}]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["PANDAS y Manejo de archivos en google colab.\n","(También veremos como hacerlo en jupyter, por lo que será necesario descargarlo)"],"metadata":{"id":"Cl3N8ykjiO3f"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"m1FzRPJKShUG","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687217178489,"user_tz":360,"elapsed":165,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"98543c32-5cdc-40ea-bf87-fd635385af53"},"outputs":[{"output_type":"stream","name":"stdout","text":[" Team \"Payroll (millions)\" \"Wins\"\n","0 Nationals 81.34 98\n","1 Reds 82.20 97\n","2 Yankees 197.96 95\n","3 Giants 117.62 94\n","4 Braves 83.31 94\n"]}],"source":["import pandas as pd #Importamos pandas como pd\n","\n","# Leer datos de una URL en un DataFrame\n","url = \"https://people.sc.fsu.edu/~jburkardt/data/csv/mlb_teams_2012.csv\"\n","Df = pd.read_csv(url) #Función que se usa para convertir el archivo csv a un Dataframe\n","\n","print(Df.head()) # Imprimir las primeras 5 filas del DataFrame (head se refiere a encabezado)\n"]},{"cell_type":"code","source":["type(Df) #Qué tipo de variable es Df?"],"metadata":{"id":"f2Th1lgsiweN","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687217228409,"user_tz":360,"elapsed":166,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"e84bedd0-f6b7-4d16-b4e4-50e5bbeebbb3"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["pandas.core.frame.DataFrame"]},"metadata":{},"execution_count":5}]},{"cell_type":"code","source":["Df.columns #Podemos usar el método .columns para conocer el nombre de las columnas"],"metadata":{"id":"qhzUEJ81jHpe","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687217271930,"user_tz":360,"elapsed":244,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"6fe44e11-09f2-4e61-80e0-7bab1d07fbe7"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["Index(['Team', ' \"Payroll (millions)\"', ' \"Wins\"'], dtype='object')"]},"metadata":{},"execution_count":6}]},{"cell_type":"code","source":["Df[' \"Wins\"'] #Selecciona la columna de ' \"Wins\"'"],"metadata":{"id":"9sdDbRTHkqSD","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687217421352,"user_tz":360,"elapsed":193,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"e4d5c1f7-a537-4d13-8e39-96364e8ef60c"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["0 98\n","1 97\n","2 95\n","3 94\n","4 94\n","5 94\n","6 93\n","7 93\n","8 90\n","9 89\n","10 88\n","11 88\n","12 86\n","13 85\n","14 83\n","15 81\n","16 81\n","17 79\n","18 76\n","19 75\n","20 74\n","21 73\n","22 72\n","23 69\n","24 69\n","25 68\n","26 66\n","27 64\n","28 61\n","29 55\n","Name: \"Wins\", dtype: int64"]},"metadata":{},"execution_count":9}]},{"cell_type":"code","source":["Df=Df.rename(columns={' \"Wins\"':'Juegos Ganados'})#podemos usar el método de rename para cambiar el nombre de una columna, por ejemplo cambiemos ese por Juegos Ganados"],"metadata":{"id":"m2MkAMZmk8hd"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["Df=Df.rename(columns={' \"Payroll (millions)\"':'Ganancia (millones)'}) #Cambiemos también la columna de \"Payroll (millions)\"' a Ganancia (millones)"],"metadata":{"id":"SKkX9Xd-lq0B"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["Df=Df.rename(columns={'Team':'Equipo'})"],"metadata":{"id":"rIhZL2UHAi5d"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["Df.head()"],"metadata":{"id":"f75Or5eJmLRQ","colab":{"base_uri":"https://localhost:8080/","height":206},"executionInfo":{"status":"ok","timestamp":1687217792086,"user_tz":360,"elapsed":166,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"a33f1ed0-65bd-418a-9364-34af00567e70"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Equipo Ganancia (millones) Juegos Ganados\n","0 Nationals 81.34 98\n","1 Reds 82.20 97\n","2 Yankees 197.96 95\n","3 Giants 117.62 94\n","4 Braves 83.31 94"],"text/html":["\n"," <div id=\"df-ffbd05e6-7bec-400e-a1e3-e14f15d5b29c\">\n"," <div class=\"colab-df-container\">\n"," <div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Equipo</th>\n"," <th>Ganancia (millones)</th>\n"," <th>Juegos Ganados</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>Nationals</td>\n"," <td>81.34</td>\n"," <td>98</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>Reds</td>\n"," <td>82.20</td>\n"," <td>97</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>Yankees</td>\n"," <td>197.96</td>\n"," <td>95</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>Giants</td>\n"," <td>117.62</td>\n"," <td>94</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>Braves</td>\n"," <td>83.31</td>\n"," <td>94</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-ffbd05e6-7bec-400e-a1e3-e14f15d5b29c')\"\n"," title=\"Convert this dataframe to an interactive table.\"\n"," style=\"display:none;\">\n"," \n"," <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n"," <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n"," </svg>\n"," </button>\n"," \n"," <style>\n"," .colab-df-container {\n"," display:flex;\n"," flex-wrap:wrap;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\n"," const buttonEl =\n"," document.querySelector('#df-ffbd05e6-7bec-400e-a1e3-e14f15d5b29c button.colab-df-convert');\n"," buttonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function convertToInteractive(key) {\n"," const element = document.querySelector('#df-ffbd05e6-7bec-400e-a1e3-e14f15d5b29c');\n"," const dataTable =\n"," await google.colab.kernel.invokeFunction('convertToInteractive',\n"," [key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n"," + ' to learn more about interactive tables.';\n"," element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n"," await google.colab.output.renderOutput(dataTable, element);\n"," const docLink = document.createElement('div');\n"," docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n"," </script>\n"," </div>\n"," </div>\n"," "]},"metadata":{},"execution_count":17}]},{"cell_type":"code","source":["# Descargar el DataFrame en un archivo CSV\n","Df.to_csv(\"ejemplo.csv\", index=False) #Lo envía a un csv\n","\n","from google.colab import files #Libreria para manejar archivos"],"metadata":{"id":"x3NouzycSkCz"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["files.download('ejemplo.csv') #Descargamos el archivo al dispositivo"],"metadata":{"id":"yGWAiccchv79","colab":{"base_uri":"https://localhost:8080/","height":17},"executionInfo":{"status":"ok","timestamp":1687218221399,"user_tz":360,"elapsed":182,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"373661e0-a58d-4f9d-cb43-7ea017a026ce"},"execution_count":null,"outputs":[{"output_type":"display_data","data":{"text/plain":["<IPython.core.display.Javascript object>"],"application/javascript":["\n"," async function download(id, filename, size) {\n"," if (!google.colab.kernel.accessAllowed) {\n"," return;\n"," }\n"," const div = document.createElement('div');\n"," const label = document.createElement('label');\n"," label.textContent = `Downloading \"${filename}\": `;\n"," div.appendChild(label);\n"," const progress = document.createElement('progress');\n"," progress.max = size;\n"," div.appendChild(progress);\n"," document.body.appendChild(div);\n","\n"," const buffers = [];\n"," let downloaded = 0;\n","\n"," const channel = await google.colab.kernel.comms.open(id);\n"," // Send a message to notify the kernel that we're ready.\n"," channel.send({})\n","\n"," for await (const message of channel.messages) {\n"," // Send a message to notify the kernel that we're ready.\n"," channel.send({})\n"," if (message.buffers) {\n"," for (const buffer of message.buffers) {\n"," buffers.push(buffer);\n"," downloaded += buffer.byteLength;\n"," progress.value = downloaded;\n"," }\n"," }\n"," }\n"," const blob = new Blob(buffers, {type: 'application/binary'});\n"," const a = document.createElement('a');\n"," a.href = window.URL.createObjectURL(blob);\n"," a.download = filename;\n"," div.appendChild(a);\n"," a.click();\n"," div.remove();\n"," }\n"," "]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["<IPython.core.display.Javascript object>"],"application/javascript":["download(\"download_09042ab2-d2fe-47e0-8cd2-ce83c05ab464\", \"ejemplo.csv\", 554)"]},"metadata":{}}]},{"cell_type":"code","source":["Df[['Equipo','Juegos Ganados']]#Selecciona las columnas de Team y de Juegos Ganados, el doble corchete es necesario"],"metadata":{"id":"etbkOC7mh2-a","colab":{"base_uri":"https://localhost:8080/","height":990},"executionInfo":{"status":"ok","timestamp":1687218551899,"user_tz":360,"elapsed":218,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"4a8f6f1a-fb99-4d25-bb5b-40cc1d054e9b"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Equipo Juegos Ganados\n","0 Nationals 98\n","1 Reds 97\n","2 Yankees 95\n","3 Giants 94\n","4 Braves 94\n","5 Athletics 94\n","6 Rangers 93\n","7 Orioles 93\n","8 Rays 90\n","9 Angels 89\n","10 Tigers 88\n","11 Cardinals 88\n","12 Dodgers 86\n","13 White Sox 85\n","14 Brewers 83\n","15 Phillies 81\n","16 Diamondbacks 81\n","17 Pirates 79\n","18 Padres 76\n","19 Mariners 75\n","20 Mets 74\n","21 Blue Jays 73\n","22 Royals 72\n","23 Marlins 69\n","24 Red Sox 69\n","25 Indians 68\n","26 Twins 66\n","27 Rockies 64\n","28 Cubs 61\n","29 Astros 55"],"text/html":["\n"," <div id=\"df-107e032f-08c6-4457-8ee6-6f86526e5fd6\">\n"," <div class=\"colab-df-container\">\n"," <div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Equipo</th>\n"," <th>Juegos Ganados</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>Nationals</td>\n"," <td>98</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>Reds</td>\n"," <td>97</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>Yankees</td>\n"," <td>95</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>Giants</td>\n"," <td>94</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>Braves</td>\n"," <td>94</td>\n"," </tr>\n"," <tr>\n"," <th>5</th>\n"," <td>Athletics</td>\n"," <td>94</td>\n"," </tr>\n"," <tr>\n"," <th>6</th>\n"," <td>Rangers</td>\n"," <td>93</td>\n"," </tr>\n"," <tr>\n"," <th>7</th>\n"," <td>Orioles</td>\n"," <td>93</td>\n"," </tr>\n"," <tr>\n"," <th>8</th>\n"," <td>Rays</td>\n"," <td>90</td>\n"," </tr>\n"," <tr>\n"," <th>9</th>\n"," <td>Angels</td>\n"," <td>89</td>\n"," </tr>\n"," <tr>\n"," <th>10</th>\n"," <td>Tigers</td>\n"," <td>88</td>\n"," </tr>\n"," <tr>\n"," <th>11</th>\n"," <td>Cardinals</td>\n"," <td>88</td>\n"," </tr>\n"," <tr>\n"," <th>12</th>\n"," <td>Dodgers</td>\n"," <td>86</td>\n"," </tr>\n"," <tr>\n"," <th>13</th>\n"," <td>White Sox</td>\n"," <td>85</td>\n"," </tr>\n"," <tr>\n"," <th>14</th>\n"," <td>Brewers</td>\n"," <td>83</td>\n"," </tr>\n"," <tr>\n"," <th>15</th>\n"," <td>Phillies</td>\n"," <td>81</td>\n"," </tr>\n"," <tr>\n"," <th>16</th>\n"," <td>Diamondbacks</td>\n"," <td>81</td>\n"," </tr>\n"," <tr>\n"," <th>17</th>\n"," <td>Pirates</td>\n"," <td>79</td>\n"," </tr>\n"," <tr>\n"," <th>18</th>\n"," <td>Padres</td>\n"," <td>76</td>\n"," </tr>\n"," <tr>\n"," <th>19</th>\n"," <td>Mariners</td>\n"," <td>75</td>\n"," </tr>\n"," <tr>\n"," <th>20</th>\n"," <td>Mets</td>\n"," <td>74</td>\n"," </tr>\n"," <tr>\n"," <th>21</th>\n"," <td>Blue Jays</td>\n"," <td>73</td>\n"," </tr>\n"," <tr>\n"," <th>22</th>\n"," <td>Royals</td>\n"," <td>72</td>\n"," </tr>\n"," <tr>\n"," <th>23</th>\n"," <td>Marlins</td>\n"," <td>69</td>\n"," </tr>\n"," <tr>\n"," <th>24</th>\n"," <td>Red Sox</td>\n"," <td>69</td>\n"," </tr>\n"," <tr>\n"," <th>25</th>\n"," <td>Indians</td>\n"," <td>68</td>\n"," </tr>\n"," <tr>\n"," <th>26</th>\n"," <td>Twins</td>\n"," <td>66</td>\n"," </tr>\n"," <tr>\n"," <th>27</th>\n"," <td>Rockies</td>\n"," <td>64</td>\n"," </tr>\n"," <tr>\n"," <th>28</th>\n"," <td>Cubs</td>\n"," <td>61</td>\n"," </tr>\n"," <tr>\n"," <th>29</th>\n"," <td>Astros</td>\n"," <td>55</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-107e032f-08c6-4457-8ee6-6f86526e5fd6')\"\n"," title=\"Convert this dataframe to an interactive table.\"\n"," style=\"display:none;\">\n"," \n"," <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n"," <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n"," </svg>\n"," </button>\n"," \n"," <style>\n"," .colab-df-container {\n"," display:flex;\n"," flex-wrap:wrap;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\n"," const buttonEl =\n"," document.querySelector('#df-107e032f-08c6-4457-8ee6-6f86526e5fd6 button.colab-df-convert');\n"," buttonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function convertToInteractive(key) {\n"," const element = document.querySelector('#df-107e032f-08c6-4457-8ee6-6f86526e5fd6');\n"," const dataTable =\n"," await google.colab.kernel.invokeFunction('convertToInteractive',\n"," [key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n"," + ' to learn more about interactive tables.';\n"," element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n"," await google.colab.output.renderOutput(dataTable, element);\n"," const docLink = document.createElement('div');\n"," docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n"," </script>\n"," </div>\n"," </div>\n"," "]},"metadata":{},"execution_count":22}]},{"cell_type":"code","source":["type(Df[\"Equipo\"]) #Series: Arreglos de 1D con etiquetas"],"metadata":{"id":"f8TRsO4MolVm","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687218583446,"user_tz":360,"elapsed":160,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"54cbd7c6-fa12-495e-dac8-fcdb328414e5"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["pandas.core.series.Series"]},"metadata":{},"execution_count":24}]},{"cell_type":"code","source":["type(Df[[\"Equipo\"]]) #Dataframe de una columna (por eso al seleccionar más de una se requiere del doble corchete)"],"metadata":{"id":"q6HRGclJo_OG","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687218596691,"user_tz":360,"elapsed":6,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"bf195e9d-7dda-410a-b218-196f4f85147f"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["pandas.core.frame.DataFrame"]},"metadata":{},"execution_count":25}]},{"cell_type":"code","source":["Df[0:3] #Para seleccionar renglones se usan números, seleccionemos los 3 primeros renglones"],"metadata":{"id":"fRI9oAnDpBnn","colab":{"base_uri":"https://localhost:8080/","height":143},"executionInfo":{"status":"ok","timestamp":1687218678440,"user_tz":360,"elapsed":219,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"a7d92b32-c36d-450c-e8d9-ba4080b18fe9"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Equipo Ganancia (millones) Juegos Ganados\n","0 Nationals 81.34 98\n","1 Reds 82.20 97\n","2 Yankees 197.96 95"],"text/html":["\n"," <div id=\"df-a9249379-cb83-4154-83f4-fbd4f3f58920\">\n"," <div class=\"colab-df-container\">\n"," <div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Equipo</th>\n"," <th>Ganancia (millones)</th>\n"," <th>Juegos Ganados</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>Nationals</td>\n"," <td>81.34</td>\n"," <td>98</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>Reds</td>\n"," <td>82.20</td>\n"," <td>97</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>Yankees</td>\n"," <td>197.96</td>\n"," <td>95</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-a9249379-cb83-4154-83f4-fbd4f3f58920')\"\n"," title=\"Convert this dataframe to an interactive table.\"\n"," style=\"display:none;\">\n"," \n"," <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n"," <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n"," </svg>\n"," </button>\n"," \n"," <style>\n"," .colab-df-container {\n"," display:flex;\n"," flex-wrap:wrap;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\n"," const buttonEl =\n"," document.querySelector('#df-a9249379-cb83-4154-83f4-fbd4f3f58920 button.colab-df-convert');\n"," buttonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function convertToInteractive(key) {\n"," const element = document.querySelector('#df-a9249379-cb83-4154-83f4-fbd4f3f58920');\n"," const dataTable =\n"," await google.colab.kernel.invokeFunction('convertToInteractive',\n"," [key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n"," + ' to learn more about interactive tables.';\n"," element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n"," await google.colab.output.renderOutput(dataTable, element);\n"," const docLink = document.createElement('div');\n"," docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n"," </script>\n"," </div>\n"," </div>\n"," "]},"metadata":{},"execution_count":26}]},{"cell_type":"code","source":["Df['Juegos Ganados'][1] #Selecciona el 97"],"metadata":{"id":"W05UX98ZpgA7","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687218733217,"user_tz":360,"elapsed":3,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"efac4276-0391-4c5a-bb1b-16e436c03909"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["97"]},"metadata":{},"execution_count":28}]},{"cell_type":"code","source":["Df.iloc[1,2]#Para usar puros indices numéricos usamos iloc, van[renglones,columnas] EL I ES DE 'INDICES' 'INDEX' PRIMERO SE PONEN LOS RENGLONES Y DESPUES COLUMNAS (SI NO QUIERO USAR LETRAS Y QUIERO BUSCAR POR NUMERO SE NECESITA EL \"ILOC\")"],"metadata":{"id":"C_qsCj6HqDcM","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687218851462,"user_tz":360,"elapsed":4,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"896bd52f-5a95-4ff6-f385-63cc853e3922"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["97"]},"metadata":{},"execution_count":31}]},{"cell_type":"code","source":["Df.iloc[0:3,0:2]#Selecciona los primeros 3 renglones pero solo la columna Team y Ganancia (millones)"],"metadata":{"id":"Sm-X2JBdqa3V","colab":{"base_uri":"https://localhost:8080/","height":143},"executionInfo":{"status":"ok","timestamp":1687218938233,"user_tz":360,"elapsed":168,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"536a72e7-8a4f-41fa-f001-60d197053a8b"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Equipo Ganancia (millones)\n","0 Nationals 81.34\n","1 Reds 82.20\n","2 Yankees 197.96"],"text/html":["\n"," <div id=\"df-24213cff-8b41-4902-baac-7c5c1c8ffe0d\">\n"," <div class=\"colab-df-container\">\n"," <div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Equipo</th>\n"," <th>Ganancia (millones)</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>Nationals</td>\n"," <td>81.34</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>Reds</td>\n"," <td>82.20</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>Yankees</td>\n"," <td>197.96</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-24213cff-8b41-4902-baac-7c5c1c8ffe0d')\"\n"," title=\"Convert this dataframe to an interactive table.\"\n"," style=\"display:none;\">\n"," \n"," <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n"," <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n"," </svg>\n"," </button>\n"," \n"," <style>\n"," .colab-df-container {\n"," display:flex;\n"," flex-wrap:wrap;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\n"," const buttonEl =\n"," document.querySelector('#df-24213cff-8b41-4902-baac-7c5c1c8ffe0d button.colab-df-convert');\n"," buttonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function convertToInteractive(key) {\n"," const element = document.querySelector('#df-24213cff-8b41-4902-baac-7c5c1c8ffe0d');\n"," const dataTable =\n"," await google.colab.kernel.invokeFunction('convertToInteractive',\n"," [key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n"," + ' to learn more about interactive tables.';\n"," element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n"," await google.colab.output.renderOutput(dataTable, element);\n"," const docLink = document.createElement('div');\n"," docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n"," </script>\n"," </div>\n"," </div>\n"," "]},"metadata":{},"execution_count":32}]},{"cell_type":"code","source":["Df.iloc[0:4,[0,2]]#Selecciona los 4 primeros renglones pero de la columna Team y de la de Juegos Ganados"],"metadata":{"id":"wl3WqVMyrHJv","colab":{"base_uri":"https://localhost:8080/","height":175},"executionInfo":{"status":"ok","timestamp":1687219106738,"user_tz":360,"elapsed":168,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"d2e2cf05-7c72-4183-a38f-22ac3fd35c29"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Equipo Juegos Ganados\n","0 Nationals 98\n","1 Reds 97\n","2 Yankees 95\n","3 Giants 94"],"text/html":["\n"," <div id=\"df-e90f1f31-3a41-416d-be90-22eca57be591\">\n"," <div class=\"colab-df-container\">\n"," <div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Equipo</th>\n"," <th>Juegos Ganados</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>Nationals</td>\n"," <td>98</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>Reds</td>\n"," <td>97</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>Yankees</td>\n"," <td>95</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>Giants</td>\n"," <td>94</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-e90f1f31-3a41-416d-be90-22eca57be591')\"\n"," title=\"Convert this dataframe to an interactive table.\"\n"," style=\"display:none;\">\n"," \n"," <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n"," <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n"," </svg>\n"," </button>\n"," \n"," <style>\n"," .colab-df-container {\n"," display:flex;\n"," flex-wrap:wrap;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\n"," const buttonEl =\n"," document.querySelector('#df-e90f1f31-3a41-416d-be90-22eca57be591 button.colab-df-convert');\n"," buttonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function convertToInteractive(key) {\n"," const element = document.querySelector('#df-e90f1f31-3a41-416d-be90-22eca57be591');\n"," const dataTable =\n"," await google.colab.kernel.invokeFunction('convertToInteractive',\n"," [key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n"," + ' to learn more about interactive tables.';\n"," element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n"," await google.colab.output.renderOutput(dataTable, element);\n"," const docLink = document.createElement('div');\n"," docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n"," </script>\n"," </div>\n"," </div>\n"," "]},"metadata":{},"execution_count":34}]},{"cell_type":"code","source":["Df.loc[0:3,[\"Equipo\",\"Juegos Ganados\"]]#Con loc todo se hace con etiquetas (también los renglones)"],"metadata":{"id":"-XfLF3Xtt0YX","colab":{"base_uri":"https://localhost:8080/","height":175},"executionInfo":{"status":"ok","timestamp":1687219133980,"user_tz":360,"elapsed":293,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"95eb26e1-4907-4cd2-f583-4a3b631606f2"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Equipo Juegos Ganados\n","0 Nationals 98\n","1 Reds 97\n","2 Yankees 95\n","3 Giants 94"],"text/html":["\n"," <div id=\"df-2af549a7-68c2-4cf5-b6cb-388671ed68cd\">\n"," <div class=\"colab-df-container\">\n"," <div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Equipo</th>\n"," <th>Juegos Ganados</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>Nationals</td>\n"," <td>98</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>Reds</td>\n"," <td>97</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>Yankees</td>\n"," <td>95</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>Giants</td>\n"," <td>94</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-2af549a7-68c2-4cf5-b6cb-388671ed68cd')\"\n"," title=\"Convert this dataframe to an interactive table.\"\n"," style=\"display:none;\">\n"," \n"," <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n"," <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n"," </svg>\n"," </button>\n"," \n"," <style>\n"," .colab-df-container {\n"," display:flex;\n"," flex-wrap:wrap;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\n"," const buttonEl =\n"," document.querySelector('#df-2af549a7-68c2-4cf5-b6cb-388671ed68cd button.colab-df-convert');\n"," buttonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function convertToInteractive(key) {\n"," const element = document.querySelector('#df-2af549a7-68c2-4cf5-b6cb-388671ed68cd');\n"," const dataTable =\n"," await google.colab.kernel.invokeFunction('convertToInteractive',\n"," [key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n"," + ' to learn more about interactive tables.';\n"," element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n"," await google.colab.output.renderOutput(dataTable, element);\n"," const docLink = document.createElement('div');\n"," docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n"," </script>\n"," </div>\n"," </div>\n"," "]},"metadata":{},"execution_count":35}]},{"cell_type":"code","source":["#Pongamosle nombre a los renglones, cambiemos los indices númericos por la columna de Teams para que sea más fácil hayar la info de un equipo"],"metadata":{"id":"SvmxJhVAuA5R"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["nuevos_ind=[Df[\"Equipo\"]] #se creo una lista nueva"],"metadata":{"id":"lCQ-mgRzuG6m"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["Df.index= nuevos_ind #El m[etodo .index es para cambiar los indices de los renglones"],"metadata":{"id":"PhLzz1G4uRih"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["Df.head() #Veamos los primeros 5 renglones con head para ver como quedó"],"metadata":{"id":"2Eo-QNnquWHz","colab":{"base_uri":"https://localhost:8080/","height":238},"executionInfo":{"status":"ok","timestamp":1687219466589,"user_tz":360,"elapsed":6,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"7a7fb6a3-b2b5-4529-a680-cacf4025b551"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Equipo Ganancia (millones) Juegos Ganados\n","Equipo \n","Nationals Nationals 81.34 98\n","Reds Reds 82.20 97\n","Yankees Yankees 197.96 95\n","Giants Giants 117.62 94\n","Braves Braves 83.31 94"],"text/html":["\n"," <div id=\"df-0aedbbab-7ab9-4536-99a3-504293365be4\">\n"," <div class=\"colab-df-container\">\n"," <div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Equipo</th>\n"," <th>Ganancia (millones)</th>\n"," <th>Juegos Ganados</th>\n"," </tr>\n"," <tr>\n"," <th>Equipo</th>\n"," <th></th>\n"," <th></th>\n"," <th></th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>Nationals</th>\n"," <td>Nationals</td>\n"," <td>81.34</td>\n"," <td>98</td>\n"," </tr>\n"," <tr>\n"," <th>Reds</th>\n"," <td>Reds</td>\n"," <td>82.20</td>\n"," <td>97</td>\n"," </tr>\n"," <tr>\n"," <th>Yankees</th>\n"," <td>Yankees</td>\n"," <td>197.96</td>\n"," <td>95</td>\n"," </tr>\n"," <tr>\n"," <th>Giants</th>\n"," <td>Giants</td>\n"," <td>117.62</td>\n"," <td>94</td>\n"," </tr>\n"," <tr>\n"," <th>Braves</th>\n"," <td>Braves</td>\n"," <td>83.31</td>\n"," <td>94</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-0aedbbab-7ab9-4536-99a3-504293365be4')\"\n"," title=\"Convert this dataframe to an interactive table.\"\n"," style=\"display:none;\">\n"," \n"," <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n"," <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n"," </svg>\n"," </button>\n"," \n"," <style>\n"," .colab-df-container {\n"," display:flex;\n"," flex-wrap:wrap;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\n"," const buttonEl =\n"," document.querySelector('#df-0aedbbab-7ab9-4536-99a3-504293365be4 button.colab-df-convert');\n"," buttonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function convertToInteractive(key) {\n"," const element = document.querySelector('#df-0aedbbab-7ab9-4536-99a3-504293365be4');\n"," const dataTable =\n"," await google.colab.kernel.invokeFunction('convertToInteractive',\n"," [key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n"," + ' to learn more about interactive tables.';\n"," element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n"," await google.colab.output.renderOutput(dataTable, element);\n"," const docLink = document.createElement('div');\n"," docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n"," </script>\n"," </div>\n"," </div>\n"," "]},"metadata":{},"execution_count":45}]},{"cell_type":"code","source":["Df.loc[\"Red Sox\"] #Encuentra la info de los Red Sox"],"metadata":{"id":"hPwVhazHuYI3","colab":{"base_uri":"https://localhost:8080/","height":112},"executionInfo":{"status":"ok","timestamp":1687219505783,"user_tz":360,"elapsed":199,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"728ed18d-068f-485c-a240-5d5b38c00d4a"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Equipo Ganancia (millones) Juegos Ganados\n","Equipo \n","Red Sox Red Sox 173.18 69"],"text/html":["\n"," <div id=\"df-afca2dcf-cf40-4dee-9267-38d4ec0e1bb7\">\n"," <div class=\"colab-df-container\">\n"," <div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Equipo</th>\n"," <th>Ganancia (millones)</th>\n"," <th>Juegos Ganados</th>\n"," </tr>\n"," <tr>\n"," <th>Equipo</th>\n"," <th></th>\n"," <th></th>\n"," <th></th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>Red Sox</th>\n"," <td>Red Sox</td>\n"," <td>173.18</td>\n"," <td>69</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-afca2dcf-cf40-4dee-9267-38d4ec0e1bb7')\"\n"," title=\"Convert this dataframe to an interactive table.\"\n"," style=\"display:none;\">\n"," \n"," <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n"," <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n"," </svg>\n"," </button>\n"," \n"," <style>\n"," .colab-df-container {\n"," display:flex;\n"," flex-wrap:wrap;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\n"," const buttonEl =\n"," document.querySelector('#df-afca2dcf-cf40-4dee-9267-38d4ec0e1bb7 button.colab-df-convert');\n"," buttonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function convertToInteractive(key) {\n"," const element = document.querySelector('#df-afca2dcf-cf40-4dee-9267-38d4ec0e1bb7');\n"," const dataTable =\n"," await google.colab.kernel.invokeFunction('convertToInteractive',\n"," [key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n"," + ' to learn more about interactive tables.';\n"," element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n"," await google.colab.output.renderOutput(dataTable, element);\n"," const docLink = document.createElement('div');\n"," docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n"," </script>\n"," </div>\n"," </div>\n"," "]},"metadata":{},"execution_count":46}]},{"cell_type":"code","source":["Df=Df.sort_values('Ganancia (millones)') #Ordenemos el Df de acuerdo a la ganancia usando sort_values\n","print(Df)"],"metadata":{"id":"u4oDmRuIui9X","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687219676765,"user_tz":360,"elapsed":6,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"b3bca9dc-4655-4617-f602-658962b5c87f"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":[" Equipo Ganancia (millones) Juegos Ganados\n","Equipo \n","Padres Padres 55.24 76\n","Athletics Athletics 55.37 94\n","Astros Astros 60.65 55\n","Royals Royals 60.91 72\n","Pirates Pirates 63.43 79\n","Rays Rays 64.17 90\n","Diamondbacks Diamondbacks 74.28 81\n","Blue Jays Blue Jays 75.48 73\n","Rockies Rockies 78.06 64\n","Indians Indians 78.43 68\n","Nationals Nationals 81.34 98\n","Orioles Orioles 81.43 93\n","Mariners Mariners 81.97 75\n","Reds Reds 82.20 97\n","Braves Braves 83.31 94\n","Cubs Cubs 88.19 61\n","Mets Mets 93.35 74\n","Twins Twins 94.08 66\n","Dodgers Dodgers 95.14 86\n","White Sox White Sox 96.92 85\n","Brewers Brewers 97.65 83\n","Cardinals Cardinals 110.30 88\n","Giants Giants 117.62 94\n","Marlins Marlins 118.07 69\n","Rangers Rangers 120.51 93\n","Tigers Tigers 132.30 88\n","Angels Angels 154.49 89\n","Red Sox Red Sox 173.18 69\n","Phillies Phillies 174.54 81\n","Yankees Yankees 197.96 95\n"]}]},{"cell_type":"code","source":["Df.to_csv(\"ejemplo2.csv\", index=False) #Lo volvemos a guardar pero ahora como ejemplo2\n","files.download(\"ejemplo2.csv\")"],"metadata":{"id":"19Ww9XrywALU","colab":{"base_uri":"https://localhost:8080/","height":17},"executionInfo":{"status":"ok","timestamp":1687220270940,"user_tz":360,"elapsed":196,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"a8cb6879-0559-43f6-b32e-e82907ce7f83"},"execution_count":null,"outputs":[{"output_type":"display_data","data":{"text/plain":["<IPython.core.display.Javascript object>"],"application/javascript":["\n"," async function download(id, filename, size) {\n"," if (!google.colab.kernel.accessAllowed) {\n"," return;\n"," }\n"," const div = document.createElement('div');\n"," const label = document.createElement('label');\n"," label.textContent = `Downloading \"${filename}\": `;\n"," div.appendChild(label);\n"," const progress = document.createElement('progress');\n"," progress.max = size;\n"," div.appendChild(progress);\n"," document.body.appendChild(div);\n","\n"," const buffers = [];\n"," let downloaded = 0;\n","\n"," const channel = await google.colab.kernel.comms.open(id);\n"," // Send a message to notify the kernel that we're ready.\n"," channel.send({})\n","\n"," for await (const message of channel.messages) {\n"," // Send a message to notify the kernel that we're ready.\n"," channel.send({})\n"," if (message.buffers) {\n"," for (const buffer of message.buffers) {\n"," buffers.push(buffer);\n"," downloaded += buffer.byteLength;\n"," progress.value = downloaded;\n"," }\n"," }\n"," }\n"," const blob = new Blob(buffers, {type: 'application/binary'});\n"," const a = document.createElement('a');\n"," a.href = window.URL.createObjectURL(blob);\n"," a.download = filename;\n"," div.appendChild(a);\n"," a.click();\n"," div.remove();\n"," }\n"," "]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["<IPython.core.display.Javascript object>"],"application/javascript":["download(\"download_89f98c56-ab6a-4309-8d22-8fba172f490d\", \"ejemplo2.csv\", 554)"]},"metadata":{}}]},{"cell_type":"code","source":["#Guardemos el archivo en el drive\n","from google.colab import drive\n","drive.mount('/content/drive') #Esto nos permite que google colab reconozca nuestra carpeta como la carpeta donde está guardado el notebook en el que estamos trabajando al momento\n","ruta_guardado = '/content/drive/MyDrive/Colab Notebooks/ejemplo2.csv'\n","Df.to_csv(ruta_guardado, index=False)"],"metadata":{"id":"pcjDh9dDzYLY","colab":{"base_uri":"https://localhost:8080/","height":380},"executionInfo":{"status":"error","timestamp":1688339596753,"user_tz":360,"elapsed":3039,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"e2785cdc-9ee9-4962-bea6-e99b2e9d17b1"},"execution_count":null,"outputs":[{"output_type":"error","ename":"MessageError","evalue":"ignored","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mMessageError\u001b[0m Traceback (most recent call last)","\u001b[0;32m<ipython-input-1-ee133e5e451f>\u001b[0m in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m#Guardemos el archivo en el drive\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mgoogle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolab\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mdrive\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mdrive\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'/content/drive'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m#Esto nos permite que google colab reconozca nuestra carpeta como la carpeta donde está guardado el notebook en el que estamos trabajando al momento\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mruta_guardado\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'/content/drive/MyDrive/Colab Notebooks/ejemplo2.csv'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mDf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_csv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mruta_guardado\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/google/colab/drive.py\u001b[0m in \u001b[0;36mmount\u001b[0;34m(mountpoint, force_remount, timeout_ms, readonly)\u001b[0m\n\u001b[1;32m 101\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmount\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmountpoint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mforce_remount\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout_ms\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m120000\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreadonly\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 102\u001b[0m \u001b[0;34m\"\"\"Mount your Google Drive at the specified mountpoint path.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 103\u001b[0;31m return _mount(\n\u001b[0m\u001b[1;32m 104\u001b[0m \u001b[0mmountpoint\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 105\u001b[0m \u001b[0mforce_remount\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mforce_remount\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/google/colab/drive.py\u001b[0m in \u001b[0;36m_mount\u001b[0;34m(mountpoint, force_remount, timeout_ms, ephemeral, readonly)\u001b[0m\n\u001b[1;32m 130\u001b[0m )\n\u001b[1;32m 131\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mephemeral\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 132\u001b[0;31m _message.blocking_request(\n\u001b[0m\u001b[1;32m 133\u001b[0m \u001b[0;34m'request_auth'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrequest\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0;34m'authType'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'dfs_ephemeral'\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout_sec\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 134\u001b[0m )\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/google/colab/_message.py\u001b[0m in \u001b[0;36mblocking_request\u001b[0;34m(request_type, request, timeout_sec, parent)\u001b[0m\n\u001b[1;32m 174\u001b[0m \u001b[0mrequest_type\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrequest\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparent\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mparent\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexpect_reply\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 175\u001b[0m )\n\u001b[0;32m--> 176\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mread_reply_from_input\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrequest_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout_sec\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/google/colab/_message.py\u001b[0m in \u001b[0;36mread_reply_from_input\u001b[0;34m(message_id, timeout_sec)\u001b[0m\n\u001b[1;32m 101\u001b[0m ):\n\u001b[1;32m 102\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'error'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mreply\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 103\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mMessageError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreply\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'error'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 104\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mreply\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'data'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 105\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mMessageError\u001b[0m: Error: credential propagation was unsuccessful"]}]},{"cell_type":"markdown","source":["Vamos a crear un archivo de texto, escribir y cerrar en drive"],"metadata":{"id":"r1TiXiqq1001"}},{"cell_type":"code","source":["import os\n","os.getcwd() #Le preguntamos en que directorio estamos"],"metadata":{"id":"22zZ32rp1hj5","colab":{"base_uri":"https://localhost:8080/","height":35},"executionInfo":{"status":"ok","timestamp":1687221566962,"user_tz":360,"elapsed":178,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"c2de8fc6-adb5-44ad-d795-c2600a6f17de"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["'/content/drive/MyDrive/Colab Notebooks'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":94}]},{"cell_type":"code","source":["os.chdir(\"/content/drive/MyDrive/Colab Notebooks\") #Cambiamos el directorio a la carpeta donde queremos el archivo"],"metadata":{"id":"mZ_VmJTh16GS"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["archivo=open('nuevo.txt', 'w') #Abrimos para escribir"],"metadata":{"id":"axNiv4XT2COB"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["archivo.write('hola') #Escribimos \"hola\"\n","archivo.close #Cerramos"],"metadata":{"id":"S8G2CBuG2RGv","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687221569390,"user_tz":360,"elapsed":4,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"5e69927e-20e3-4247-9766-6d98a2a4367f"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["<function TextIOWrapper.close()>"]},"metadata":{},"execution_count":97}]},{"cell_type":"code","source":["arch2=open('nuevo.txt','r') #Ahora vamos a abrir el nuevo archivo para lectura"],"metadata":{"id":"8WYVrrdr2XeL"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["contenido = arch2.read() # Lee el contenido del archivo\n","\n","print(contenido) # Imprime el contenido del archivo\n","\n","arch2.close() # Cierra el archivo"],"metadata":{"id":"ciFrQlph2gEx","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687221571206,"user_tz":360,"elapsed":6,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"abe26b88-2a02-4b19-af99-7df9005c315c"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["\n"]}]},{"cell_type":"code","source":["type(contenido)"],"metadata":{"id":"vRK32UPx2vA_","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1687221573289,"user_tz":360,"elapsed":7,"user":{"displayName":"Roberto García Gómez","userId":"07651563382691562012"}},"outputId":"1e5a9f64-936a-4ca2-99dd-8636eb94c905"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["str"]},"metadata":{},"execution_count":100}]},{"cell_type":"code","source":[],"metadata":{"id":"kFhtbuG_PbjJ"},"execution_count":null,"outputs":[]}]}