{"id":2565,"date":"2025-10-13T18:02:46","date_gmt":"2025-10-13T16:02:46","guid":{"rendered":"https:\/\/bioinfo2.ugr.es\/biocomputacion\/?page_id=2565"},"modified":"2025-10-13T18:02:46","modified_gmt":"2025-10-13T16:02:46","slug":"generar-graficos-con-python-pandas-y-matplotlibs","status":"publish","type":"page","link":"https:\/\/alu.ugr.es\/bioinfo\/biocomputacion\/generar-graficos-con-python-pandas-y-matplotlibs\/","title":{"rendered":"DataFrames y pandas"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Un DataFrame de pandas es una estructura de datos bidimensional, similar a una tabla de una hoja de c\u00e1lculo o una base de datos, que organiza los datos en filas y columnas con etiquetas. Cada columna puede contener diferentes tipos de datos y tiene un \u00edndice (etiqueta) para las filas y otro para las columnas, lo que permite manipular datos de manera eficiente en an\u00e1lisis y ciencia de datos.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Caracter\u00edsticas principales<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><b>Estructura tabular:<\/b><span style=\"font-weight: 400\"> Se organiza en filas y columnas, como una hoja de c\u00e1lculo de Excel.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><b>Bidimensional:<\/b><span style=\"font-weight: 400\"> Es una estructura de dos dimensiones (filas y columnas).\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><b>Etiquetado:<\/b><span style=\"font-weight: 400\"> Tiene un \u00edndice para las filas y nombres para las columnas, permitiendo el acceso a los datos por etiqueta.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><b>Tipos de datos heterog\u00e9neos:<\/b><span style=\"font-weight: 400\"> Cada columna puede contener datos de diferentes tipos (por ejemplo, n\u00fameros, texto, etc.).\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><b>Similar a diccionarios de Python:<\/b><span style=\"font-weight: 400\"> Cada columna es una &#8220;Series&#8221; de pandas, y el DataFrame se puede ver como un diccionario donde las claves son las columnas y los valores son las Series.\u00a0<\/span><\/li>\n<\/ul>\n<p><strong>A trav\u00e9s de un DataFrame tenemos acceso a una serie de <a href=\"https:\/\/pandas.pydata.org\/docs\/user_guide\/visualization.html\">visualizaciones<\/a>.\u00a0<\/strong><\/p>\n<p>&nbsp;<\/p>\n<h3><span style=\"font-weight: 400\">Generar un DataFrame:<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Leer una tabla de fichero:<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400\">import<\/span><span style=\"font-weight: 400\"> pandas as pd<\/span>\n\n<span style=\"font-weight: 400\">df = pd.read_csv(<\/span><span style=\"font-weight: 400\">'data.csv'<\/span><span style=\"font-weight: 400\">) # df es un DataFrame<\/span><\/pre>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Generar un DataFrame a partir de listas<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400\">data = []<\/span>\n\n<span style=\"font-weight: 400\">for i in range(5):<\/span>\n\n<span style=\"font-weight: 400\"> \u00a0\u00a0\u00a0# generate some random data to illustrate<\/span>\n\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0a, b, c, d, e = i, i**2, i+1, i*10, i\/2<\/span>\n\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400\">data.append([a, b, c, d, e]) <\/span><span style=\"font-weight: 400\"># data es una \u2018lista de listas\u2019. La lista anidada contiene 5 elementos<\/span>\n\n<span style=\"font-weight: 400\">df = pd.DataFrame(data, columns=<\/span><span style=\"font-weight: 400\">['a', 'b', 'c', 'd', 'e']<\/span><span style=\"font-weight: 400\">)<\/span>\n\n<span style=\"font-weight: 400\">print(df)<\/span><\/pre>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Generar un DataFrame a partir de un diccionario<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400\">data={'a':[1,2],'b':[4,6]}<\/span>\n\n<span style=\"font-weight: 400\">df = pd.DataFrame(data)<\/span><\/pre>\n<p>&nbsp;<\/p>\n<pre><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Un DataFrame de pandas es una estructura de datos bidimensional, similar a una tabla de una hoja de c\u00e1lculo o una base de datos, que organiza los datos en filas y columnas con etiquetas. Cada columna puede contener diferentes tipos <a href=\"https:\/\/alu.ugr.es\/bioinfo\/biocomputacion\/generar-graficos-con-python-pandas-y-matplotlibs\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2565","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/alu.ugr.es\/bioinfo\/biocomputacion\/wp-json\/wp\/v2\/pages\/2565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alu.ugr.es\/bioinfo\/biocomputacion\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/alu.ugr.es\/bioinfo\/biocomputacion\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/alu.ugr.es\/bioinfo\/biocomputacion\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alu.ugr.es\/bioinfo\/biocomputacion\/wp-json\/wp\/v2\/comments?post=2565"}],"version-history":[{"count":0,"href":"https:\/\/alu.ugr.es\/bioinfo\/biocomputacion\/wp-json\/wp\/v2\/pages\/2565\/revisions"}],"wp:attachment":[{"href":"https:\/\/alu.ugr.es\/bioinfo\/biocomputacion\/wp-json\/wp\/v2\/media?parent=2565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}