Laboratorio 22

Crear un notebook con Copilot Chat y datos de prestamos

Este conjunto de datos tested_worldwide.csv proviene de Kaggle. Este conjunto de datos, que contiene el número de pruebas realizadas a lo largo del tiempo, es importante para ayudar a entender los casos reportados diariamente y entender cómo se está propagando realmente la COVID-19 en cada país.

Fuente validada

Lab_22_Jupyter_Notebook.docx

Esta pagina fue reconstruida desde el documento del ZIP entregado como fuente principal.

Conformidad visual

Sin imagenes publicadas

El archivo fuente contiene 0 imagenes embebidas. Para garantizar conformidad, no se publican imagenes heredadas de otros materiales.

Criterio GH-300

Practica verificable

Ejecuta los comandos, captura evidencia propia y valida cada sugerencia de Copilot antes de aceptarla.

Alcance de publicacion: Solo se publica el contenido del laboratorio indicado por el archivo Lab_22_Jupyter_Notebook.docx. Las imagenes no se muestran porque el ZIP no incluye imagenes embebidas en este documento.

Certificación GH-300

Laboratorio 22

Jupyter Notebook con GitHub Copilot Chat

Autor: Carlos Crudo

linkedin.com/in/carloscrudo

Creación y análisis de notebooks Jupyter usando GitHub Copilot Chat para generar código Python, visualizaciones y análisis de datos de prueba.

Temas que cubre este laboratorio:

Jupyter Notebook en VS Code con Copilot

Generación de código Python para data analysis

Pandas, Matplotlib con asistencia Copilot

Copilot Chat para explicación de código

Análisis exploratorio de datos (EDA)

Export a HTML / PDF desde Notebook

Laboratorio 22: Jupyter Notebook con GitHub Copilot Chat

Laboratorio 22 - Crea un cuaderno usando el chat de Github Copilot y proporciona respuestas basadas en datos de prueba INTRODUCCIÓN

Este conjunto de datos tested_worldwide.csv proviene de Kaggle. Este conjunto de datos, que contiene el número de pruebas realizadas a lo largo del tiempo, es importante para ayudar a entender los casos reportados diariamente y entender cómo se está propagando realmente la COVID-19 en cada país.

INSTRUCCIONES

Abre Visual Studio Code desde el menú de inicio de Windows y abre la carpeta navegando a C:\Labfiles\CopilotHackathon

Haz clic en el botón Sí, Confío en el autor.

Haz clic en el icono de Copilot en la esquina derecha y selecciona Github Copilot Chat.

Escribe tu prompt create a new notebook in a project. Use command /newnotebook and name it as "COVID19 Worldwide Testing Data"

Puedes ver las instrucciones del Copilot ayudándote con las instrucciones. Sigue los pasos y crea el cuaderno.

Abre la paleta de comandos pulsando Ctrl+Shift+P.

Escribe y pulsa Enter.Jupyter: Create New Blank Notebook

Se creará un nuevo cuaderno. Guárdalo con el nombre. También puedes preguntar a Copilot cómo guardar un cuaderno nuevo.COVID19WorldwideTesting Data.ipynb

Ve a la carpeta de destino - excercisefiles-? Dataengineer introduce y guarda el archivo.COVID19WorldwideTesting Data.ipynb

Deberías ver que el archivo fue creado en la carpeta de dataengineer.

Utiliza Copilot y Copilot Chat para desarrollar el ejercicio y apoyar tu aprendizaje.

EJERCICIO

Nuestro análisis intenta responder a esta pregunta: ¿Qué países han reportado el mayor número de casos positivos en relación con el número de pruebas realizadas?

Tarea 1: Importar las bibliotecas requeridas

Haz clic en el núcleo de Notebook, escribe y pulsa Enter*#Import Required Libraries.Including Pandas*

Pulsa tab. Te llevará hasta el final de la línea. Pulsa Enter y vuelve a pulsar Tab para añadir todas las bibliotecas.

# Importar las bibliotecas necesarias, incluidos los pandas.

*# Import Required Libraries*

*# Here we are importing the necessary libraries for our task*

import pandas as pd *# pandas is a software library written for the Python programming language for data manipulation and analysis.*

Tarea 2: Cargar el conjunto de datos

Usa pandas para cargar el archivo 'tested_worldwide.csv' desde el nivel raíz.

Pide ayuda a Github Copilot con cómo cargar datos. Entra Use pandas to load the 'tested_worldwide.csv' file from the root level

Introduce el siguiente código en un Notebook y ejecutalo. Te pedirá que selecciones Entorno Python. Seleccionalo.

Selecciona el entorno recomendado. El script se ejecuta y proporciona los resultados.

Tarea 3: Entender los datos

Utiliza la función head() para mostrar las primeras 5 filas del conjunto de datos

Pide a tu Copilot de Github que te ayude con el código para mostrar las primeras 5 filas del conjunto de datos. display first 5 rows of the dataset

Haz clic en + código para abrir un nuevo kerner. Solo tienes que introducir # mostrar las primeras 5 filas del conjunto de datos. Predecirá automáticamente tu pregunta. Solo pulsa etiquetar y luego pulsar Enter.

Coiplot predice el comando que buscas, así que pulsa la pestaña para aceptar el código. Siempre tienes la opción de editar/escribir tu propio código.

Pulsa la pestaña y acepta el código. Ejecuta el kernel.

Deberías ver los resultados.

Pide ayuda a tu copiloto con . Haz clic en +code, .enter el código y luego ejecuta el kernel. También puedes usar el código de abajoDisplay the number of rows and columns in the dataframe

num_rows, num_cols = data.shape

print("Number of rows:", num_rows)

print("Number of columns:", num_cols)

Pide ayuda a tu copiloto con esto. También puedes usar Display the data types of each columndata.dttypes

Pide a tu Copilot de GitHub que proporcione el código para Display the number of missing values in each column.

Añade un nuevo kernel, añade el código de abajo y ejecuta. También puedes usar el código sugerido por Copilot y comprobar

missing_values = df.isnull().sum()

print(missing_values)

Ejecuta el código de abajo en el nuevo núcleo para mostrar el número de valores únicos en cada columna. Consulta con tu copiloto sobre el código y los resultados.

unique_values = df.nunique()

print(unique_values)

Tarea 4: Limpieza de datos

Ejecuta el código de abajo para eliminar las columnas que no sean necesarias para el análisis. Pídele el código a tu copiloto y revisa los resultados.

data = df[['Country_Region', 'positive', 'total_tested']]

Escribe un nuevo kernel y acepta el código.*#Rename the columns to make them more readable*

Puedes usar el código de abajo y ejecutarlo.

df.rename(columns={'Country_Region': 'Country', 'positive': 'Positive Cases', 'total_tested': 'Total Tested'}, inplace=True)

Pide a tu copiloto que ejecute el código en un nuevo kernel o escribe En el nuevo kernel y pulsa enter. Pulsa la pestaña y acepta el códigoDrop the rows that have missing values*#Drop the rows that have missing values*

Añade un nuevo núcleo +Code y escribe, pulsa etiqueta para aceptar el código, vuelve a enter y pulsa tab. Genera código para casos positivos, Total de pruebas y país, y luego ejecutalo.*#Convert the data types of the columns to the appropriate types*

Añade un nuevo núcleo +Code y escribe Y pulsa Enter. Pulsa tab y acepta el código. También puedes preguntar en el chat de GitHub Copilot*#Display the number of missing values in each column*

Tarea 5: Extraer los diez países con más casos de Covid-19.

Pide a tu chat de Copilot que te ayude con el código o abre un código nuevo y escribe y pulsa Etner. Pulsa tab para acceder al código.Create a new dataframe that contains the total number of positive cases for each country*#Create a new dataframe that contains the total number of positive cases for each country*

En un código nuevo, introduce debajo de los prompts y entra después de cada prompt para aceptar el código y ejecutarlo.

*# Group the data by 'Country' and calculate the sum of 'Positive Cases'*

total_positive_cases = data.groupby('Country')['Positive Cases'].sum()

*# Create a new dataframe with the total positive cases for each country*

df_total_positive_cases = pd.DataFrame({'Country': total_positive_cases.index, 'Total Positive Cases': total_positive_cases.values})

*# Display the new dataframe*

df_total_positive_cases

Pide a Copilot que escriba el nuevo kernel de código, pulsa etiqueta para aceptar el código y ejecutarlo.Sort the dataframe in descending order of the total number of positive cases*# Sort the dataframe in descending order of the total number of positive cases*

Pide a tu chat de Github Copilot que te ayude con el O escribe nuevo kernel de código y reúsalo. Recuerda que solo necesitas exhibir.Display the top ten countries with the most positive cases*# Display the top ten countries with the most positive cases*

Tarea 6: Identificar el mayor índice de positivos en casos testados

Pide ayuda en tu chat de GitHub Copilot o abre un nuevo núcleo de código y escribe y pulsa tab para acceder al código. Puedes editar el código si es necesario y ejecutarlo.Create a new dataframe that contains the total number of tests conducted for each country*# Create a new dataframe that contains the total number of tests conducted for each country*

*# Group the data by 'Country' and calculate the sum of 'Total Tested'*

total_tests = data.groupby('Country')['Total Tested'].sum()

*# Create a new dataframe with the total tests conducted for each country*

df_total_tests = pd.DataFrame({'Country': total_tests.index, 'Total Tests': total_tests.values})

*# Display the new dataframe*

df_total_tests

Pregunta en tu chat de Github Copilot o abre un nuevo kernel de código, escribe Y pulsa tab para hacer caccep al código y ejecutarlo.Sort the dataframe in descending order of the total number of tests conducted*# Sort the dataframe in descending order of the total number of tests conducted*

Pregunta en tu chat de Github Copilot o abre un nuevo kernel de código, escribe Y pulsa tab para hacer caccep al código y ejecutarlo.Display the top ten countries with the most tests conducted*# Display the top ten countries with the most tests conducted*

Tarea 7: Identificar los tres principales países que han tenido el mayor número de casos positivos frente al número de pruebas realizadas

Pregunta en el chat de Github Copilot o abre un nuevo núcleo de código y escribe Y pulsa tab para hacer caccep al código y ejecutarlo.Merge the two dataframes created in the previous steps*# Display the top ten countries with the most tests conducted*

Pregunta a tu chat de Github Copilot o abre un nuevo núcleo de código y escribe Y pulsa tab para aceptar el código y ejecutarlo.Create a new column that contains the ratio of positive cases to the number of tests conducted*# Create a new column that contains the ratio of positive cases to the number of tests conducted*

Pregunta a tu chat de Github Copilot o abre un nuevo núcleo de código y escribe Y pulsa la pestaña para aceptar el código y ejecutarlo.Sort the dataframe in descending order of the ratio of positive cases to the number of tests conducted*# Sort the dataframe in descending order of the ratio of positive cases to the number of tests conducted*

Pregunta a tu chat de Github Copilot O abre un nuevo núcleo de código y escribe Y pulsa la pestaña para aceptar el código y ejecutarloDisplay the top three countries with the highest ratio of positive cases to the number of tests conducted*#Display the top three countries with the highest ratio of positive cases to the number of tests conducted*

*#Display the top three countries with the highest ratio of positive cases to the number of tests conducted*

top_countries = merged_df.nlargest(3, 'Positive Test Rate')

top_countries[['Country', 'Positive Test Rate']]

Tarea 8: Mostrar los resultados

Pide a tu chat de Github Copilot o abre un nuevo kernel de código y escribe Y pulsa la pestaña para aceptar el código y ejecutarloDisplay the results a chart that shows the top three countries with the highest ratio of positive cases to the number*# Display the results a chart that shows the top three countries with the highest ratio of positive cases to the number*

*#Display the results a chart that shows the top three countries with the highest ratio of positive cases to the number*

import matplotlib.pyplot as plt

top_countries.plot(x='Country', y='Positive Test Rate', kind='bar')

Pide a tu chat de Github Copilot o abre un nuevo kernel de código y escribe Y pulsa la pestaña para aceptar el código y ejecutarloDisplay the results in a chart that shows the top ten countries with the most positive cases*# Display the results in a chart that shows the top ten countries with the most positive cases*

*#Display the results in a chart that shows the top ten countries with the most positive cases*

import matplotlib.pyplot as plt

df_total_positive_cases.head(10).plot(x='Country', y='Total Positive Cases', kind='bar')

plt.xlabel('Country')

plt.ylabel('Total Positive Cases')

plt.title('Top Ten Countries with the Most Positive Cases')

plt.show()

Pide a tu chat de Github Copilot o abre un nuevo kernel de código y escribe Y pulsa la pestaña para aceptar el código y ejecutarloDisplay the results in a chart that shows the top ten countries with the most tests conducted*# Display the results in a chart that shows the top ten countries with the most tests conducted*

Tarea 9: Conclusión

¿Cuáles son tus conclusiones?

¿Cuáles son las limitaciones de este análisis?

¿Cuáles son los siguientes pasos que darías para mejorar este análisis?