You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Actualizamos los paquetes necesarios. En general esto no hace falta en Google Colab, pero sí en Jupyter Notebook."
58
60
]
59
61
},
60
62
{
61
63
"cell_type": "code",
62
64
"execution_count": null,
63
-
"metadata": {},
65
+
"metadata": {
66
+
"id": "PbeHGejDBO6x"
67
+
},
64
68
"outputs": [],
65
69
"source": [
66
70
"!sudo apt-get update -qq"
@@ -69,7 +73,9 @@
69
73
{
70
74
"cell_type": "code",
71
75
"execution_count": null,
72
-
"metadata": {},
76
+
"metadata": {
77
+
"id": "40eR4mfVBO6y"
78
+
},
73
79
"outputs": [],
74
80
"source": [
75
81
"!sudo apt-get install -y p7zip"
@@ -78,7 +84,9 @@
78
84
{
79
85
"cell_type": "code",
80
86
"execution_count": null,
81
-
"metadata": {},
87
+
"metadata": {
88
+
"id": "DSBkYju1BO6z"
89
+
},
82
90
"outputs": [],
83
91
"source": [
84
92
"RunningInCOLAB = 'google.colab' in str(get_ipython()) if hasattr(__builtins__,'__IPYTHON__') else False"
@@ -803,7 +811,7 @@
803
811
},
804
812
"outputs": [],
805
813
"source": [
806
-
"firstdate = dfwiki[0][1][5]\n",
814
+
"firstdate = dfwiki[0][1][4]\n",
807
815
"firstdate"
808
816
]
809
817
},
@@ -999,7 +1007,9 @@
999
1007
},
1000
1008
{
1001
1009
"cell_type": "markdown",
1002
-
"metadata": {},
1010
+
"metadata": {
1011
+
"id": "TbOKByplBO7Q"
1012
+
},
1003
1013
"source": [
1004
1014
"## Datos de Stackoverflow\n",
1005
1015
"\n",
@@ -1012,22 +1022,28 @@
1012
1022
},
1013
1023
{
1014
1024
"cell_type": "markdown",
1015
-
"metadata": {},
1025
+
"metadata": {
1026
+
"id": "ToYeCqMNBO7R"
1027
+
},
1016
1028
"source": [
1017
1029
"## Descarga de los datos"
1018
1030
]
1019
1031
},
1020
1032
{
1021
1033
"cell_type": "markdown",
1022
-
"metadata": {},
1034
+
"metadata": {
1035
+
"id": "JQvTT2bOBO7R"
1036
+
},
1023
1037
"source": [
1024
1038
"En este caso los datos están disponibles en un repositorio git. Se pueden descargar también de la Web, pero se van actualizando. Los descargamos del repositorio git para que todos tengáis los mismos."
"Podemos inspeccionar los ficheros `.xml` para ver su contenido. Son XML, sí, pero ¿con qué formato?"
1077
1103
]
1078
1104
},
1079
1105
{
1080
1106
"cell_type": "code",
1081
1107
"execution_count": null,
1082
-
"metadata": {},
1108
+
"metadata": {
1109
+
"id": "9gnbcXYIBO7U"
1110
+
},
1083
1111
"outputs": [],
1084
1112
"source": [
1085
1113
"!head Posts.xml"
1086
1114
]
1087
1115
},
1088
1116
{
1089
1117
"cell_type": "markdown",
1090
-
"metadata": {},
1118
+
"metadata": {
1119
+
"id": "ApKHu1ZgBO7U"
1120
+
},
1091
1121
"source": [
1092
1122
"Aunque se puede procesar el formato XML, lo que podemos ver es que cada entrada es exactamente una línea que comienza por \"`<row`\", y que contiene un conjunto de atributos en formato \"`atributo=\"valor\"`\". Si lo comprobamos, incluso no existirá ninguna comilla doble **dentro** de otra comilla doble, así que podemos extraer esos pares de forma facil.\n",
"Hay que extraer el conjunto de atributos para saber qué columnas tendrá nuestra tabla/CSV o archivo JSON. Recuérdese que las dos primeras filas del archivo XML tenían diferentes atributos. ¿Cómo se haría esto?"
1144
1182
]
1145
1183
},
1146
1184
{
1147
1185
"cell_type": "code",
1148
1186
"execution_count": null,
1149
-
"metadata": {},
1187
+
"metadata": {
1188
+
"id": "5Wo1jPDQBO7Y"
1189
+
},
1150
1190
"outputs": [],
1151
1191
"source": [
1152
1192
"from typing import Iterator\n",
@@ -1162,31 +1202,39 @@
1162
1202
},
1163
1203
{
1164
1204
"cell_type": "markdown",
1165
-
"metadata": {},
1205
+
"metadata": {
1206
+
"id": "yHBXA4dfBO7Y"
1207
+
},
1166
1208
"source": [
1167
1209
"El conjunto de atributos es pues:"
1168
1210
]
1169
1211
},
1170
1212
{
1171
1213
"cell_type": "code",
1172
1214
"execution_count": null,
1173
-
"metadata": {},
1215
+
"metadata": {
1216
+
"id": "nUUkPSMyBO7Y"
1217
+
},
1174
1218
"outputs": [],
1175
1219
"source": [
1176
1220
"all_attrs"
1177
1221
]
1178
1222
},
1179
1223
{
1180
1224
"cell_type": "markdown",
1181
-
"metadata": {},
1225
+
"metadata": {
1226
+
"id": "BwLQrOr2BO7Y"
1227
+
},
1182
1228
"source": [
1183
1229
"Como sabemos que el atributo `Id` va a ser la clave primaria, lo ponemos al principio. Además, generamos una lista, no un conjunto, para que el orden sea conocido."
1184
1230
]
1185
1231
},
1186
1232
{
1187
1233
"cell_type": "code",
1188
1234
"execution_count": null,
1189
-
"metadata": {},
1235
+
"metadata": {
1236
+
"id": "zPjVuHr5BO7Z"
1237
+
},
1190
1238
"outputs": [],
1191
1239
"source": [
1192
1240
"all_attrs.remove('Id')\n",
@@ -1197,14 +1245,18 @@
1197
1245
},
1198
1246
{
1199
1247
"cell_type": "markdown",
1200
-
"metadata": {},
1248
+
"metadata": {
1249
+
"id": "rjFN1ERBBO7Z"
1250
+
},
1201
1251
"source": [
1202
1252
"## Escritura del formato CSV"
1203
1253
]
1204
1254
},
1205
1255
{
1206
1256
"cell_type": "markdown",
1207
-
"metadata": {},
1257
+
"metadata": {
1258
+
"id": "lRiaGxTKBO7Z"
1259
+
},
1208
1260
"source": [
1209
1261
"El formato CSV está especificado en el estándar RFC 4180. https://www.ietf.org/rfc/rfc4180.txt. En general se puede utilizar la biblioteca `csv` de Python 3 y vamos a exportar una línea de cabecera con todos los campos. https://docs.python.org/3/library/csv.html.\n",
"El formato Parquet (https://parquet.apache.org) se ha popularizado recientemente con el uso de fuentes de datos en Internet. En general supone una mejora en todos los aspectos con respecto a CSV y en otros con respecto a JSON y JSON lines.\n",
0 commit comments