Datasets:
Tags:
Not-For-All-Audiences
Upload make_txt_files_from_parquet.ipynb
Browse files
make_txt_files_from_parquet.ipynb
CHANGED
|
@@ -727,7 +727,7 @@
|
|
| 727 |
"print(\"\\nFirst 3 rows:\")\n",
|
| 728 |
"display(df.head(3))"
|
| 729 |
],
|
| 730 |
-
"execution_count":
|
| 731 |
"outputs": [
|
| 732 |
{
|
| 733 |
"output_type": "stream",
|
|
@@ -907,6 +907,30 @@
|
|
| 907 |
}
|
| 908 |
]
|
| 909 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 910 |
{
|
| 911 |
"cell_type": "code",
|
| 912 |
"metadata": {
|
|
@@ -981,7 +1005,7 @@
|
|
| 981 |
"\n",
|
| 982 |
"print(f\"\\nProcessing completed. Created {len(txt_files_created)} text files and zipped them into {zip_path}\")"
|
| 983 |
],
|
| 984 |
-
"execution_count":
|
| 985 |
"outputs": [
|
| 986 |
{
|
| 987 |
"output_type": "stream",
|
|
@@ -1118,7 +1142,7 @@
|
|
| 1118 |
")\n",
|
| 1119 |
"print(f\"Downloaded file to: {file_path}\")"
|
| 1120 |
],
|
| 1121 |
-
"execution_count":
|
| 1122 |
"outputs": [
|
| 1123 |
{
|
| 1124 |
"output_type": "display_data",
|
|
@@ -1215,6 +1239,122 @@
|
|
| 1215 |
],
|
| 1216 |
"execution_count": null,
|
| 1217 |
"outputs": []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1218 |
}
|
| 1219 |
]
|
| 1220 |
}
|
|
|
|
| 727 |
"print(\"\\nFirst 3 rows:\")\n",
|
| 728 |
"display(df.head(3))"
|
| 729 |
],
|
| 730 |
+
"execution_count": null,
|
| 731 |
"outputs": [
|
| 732 |
{
|
| 733 |
"output_type": "stream",
|
|
|
|
| 907 |
}
|
| 908 |
]
|
| 909 |
},
|
| 910 |
+
{
|
| 911 |
+
"cell_type": "code",
|
| 912 |
+
"source": [
|
| 913 |
+
"from google.colab import drive\n",
|
| 914 |
+
"drive.mount('/content/drive')"
|
| 915 |
+
],
|
| 916 |
+
"metadata": {
|
| 917 |
+
"colab": {
|
| 918 |
+
"base_uri": "https://localhost:8080/"
|
| 919 |
+
},
|
| 920 |
+
"id": "8zNty4Fjmz8J",
|
| 921 |
+
"outputId": "4976483f-ea1c-4fd4-d9f1-1085b2a200bb"
|
| 922 |
+
},
|
| 923 |
+
"execution_count": 1,
|
| 924 |
+
"outputs": [
|
| 925 |
+
{
|
| 926 |
+
"output_type": "stream",
|
| 927 |
+
"name": "stdout",
|
| 928 |
+
"text": [
|
| 929 |
+
"Mounted at /content/drive\n"
|
| 930 |
+
]
|
| 931 |
+
}
|
| 932 |
+
]
|
| 933 |
+
},
|
| 934 |
{
|
| 935 |
"cell_type": "code",
|
| 936 |
"metadata": {
|
|
|
|
| 1005 |
"\n",
|
| 1006 |
"print(f\"\\nProcessing completed. Created {len(txt_files_created)} text files and zipped them into {zip_path}\")"
|
| 1007 |
],
|
| 1008 |
+
"execution_count": null,
|
| 1009 |
"outputs": [
|
| 1010 |
{
|
| 1011 |
"output_type": "stream",
|
|
|
|
| 1142 |
")\n",
|
| 1143 |
"print(f\"Downloaded file to: {file_path}\")"
|
| 1144 |
],
|
| 1145 |
+
"execution_count": null,
|
| 1146 |
"outputs": [
|
| 1147 |
{
|
| 1148 |
"output_type": "display_data",
|
|
|
|
| 1239 |
],
|
| 1240 |
"execution_count": null,
|
| 1241 |
"outputs": []
|
| 1242 |
+
},
|
| 1243 |
+
{
|
| 1244 |
+
"cell_type": "code",
|
| 1245 |
+
"metadata": {
|
| 1246 |
+
"id": "ff7cb87e",
|
| 1247 |
+
"outputId": "f84071d5-fe27-4238-be22-0ff0c962f5a9",
|
| 1248 |
+
"colab": {
|
| 1249 |
+
"base_uri": "https://localhost:8080/"
|
| 1250 |
+
}
|
| 1251 |
+
},
|
| 1252 |
+
"source": [
|
| 1253 |
+
"import os\n",
|
| 1254 |
+
"import re\n",
|
| 1255 |
+
"import glob\n",
|
| 1256 |
+
"import zipfile\n",
|
| 1257 |
+
"import shutil\n",
|
| 1258 |
+
"import pandas as pd\n",
|
| 1259 |
+
"\n",
|
| 1260 |
+
"# Define the input character files\n",
|
| 1261 |
+
"character_files = [\n",
|
| 1262 |
+
" \"/content/drive/MyDrive/characters/callie__splatoon_05aa14a2.parquet\",\n",
|
| 1263 |
+
" \"/content/drive/MyDrive/characters/coco_bandicoot_c128c24c.parquet\",\n",
|
| 1264 |
+
" \"/content/drive/MyDrive/characters/holo__spice_and_wolf_86b4e8a6.parquet\",\n",
|
| 1265 |
+
" \"/content/drive/MyDrive/characters/loona__helluva_boss_d778e3d3.parquet\",\n",
|
| 1266 |
+
" \"/content/drive/MyDrive/characters/mrs__katswell_523319ca.parquet\",\n",
|
| 1267 |
+
" \"/content/drive/MyDrive/characters/nanachi_a8234c45.parquet\",\n",
|
| 1268 |
+
" \"/content/drive/MyDrive/characters/nicole_watterson_6c3b3721.parquet\",\n",
|
| 1269 |
+
" \"/content/drive/MyDrive/characters/rumi_usagiyama_42e3daa7.parquet\",\n",
|
| 1270 |
+
" \"/content/drive/MyDrive/characters/samus_aran_8ffbf78e.parquet\",\n",
|
| 1271 |
+
" \"/content/drive/MyDrive/characters/shantae_d86aab10.parquet\",\n",
|
| 1272 |
+
" \"/content/drive/MyDrive/characters/sybil__pseudoregalia_e45e2e2c.parquet\",\n",
|
| 1273 |
+
" \"/content/drive/MyDrive/characters/tawna_bandicoot_5e823dce.parquet\"\n",
|
| 1274 |
+
"]\n",
|
| 1275 |
+
"\n",
|
| 1276 |
+
"# Destination folder on Drive\n",
|
| 1277 |
+
"drive_output_dir = \"/content/drive/MyDrive/characters\"\n",
|
| 1278 |
+
"os.makedirs(drive_output_dir, exist_ok=True)\n",
|
| 1279 |
+
"\n",
|
| 1280 |
+
"# Pattern for cleaning bad symbols\n",
|
| 1281 |
+
"allowed_pattern = re.compile(r'[^a-zA-Z0-9.!_?|,\\s]')\n",
|
| 1282 |
+
"\n",
|
| 1283 |
+
"for file_path in character_files:\n",
|
| 1284 |
+
" if not os.path.exists(file_path):\n",
|
| 1285 |
+
" print(f\"File not found: {file_path}\")\n",
|
| 1286 |
+
" continue\n",
|
| 1287 |
+
"\n",
|
| 1288 |
+
" # Get clean character name by stripping hashcode\n",
|
| 1289 |
+
" # e.g., 'callie__splatoon_05aa14a2' -> 'callie__splatoon'\n",
|
| 1290 |
+
" base_name = os.path.basename(file_path).replace(\".parquet\", \"\")\n",
|
| 1291 |
+
" char_name = re.sub(r'_[a-f0-9]{8}$', '', base_name)\n",
|
| 1292 |
+
"\n",
|
| 1293 |
+
" print(f\"Processing: {char_name}\")\n",
|
| 1294 |
+
"\n",
|
| 1295 |
+
" # Temporary directory to store txt files for this character\n",
|
| 1296 |
+
" temp_char_dir = f\"/content/temp_{char_name}\"\n",
|
| 1297 |
+
" os.makedirs(temp_char_dir, exist_ok=True)\n",
|
| 1298 |
+
"\n",
|
| 1299 |
+
" df = pd.read_parquet(file_path)\n",
|
| 1300 |
+
" txt_files_created = []\n",
|
| 1301 |
+
"\n",
|
| 1302 |
+
" for col in df.columns:\n",
|
| 1303 |
+
" # 'col' represents the rating (safe, questionable, explicit)\n",
|
| 1304 |
+
" descriptions = df[col].dropna().astype(str).str.strip().tolist()\n",
|
| 1305 |
+
"\n",
|
| 1306 |
+
" cleaned_descriptions = []\n",
|
| 1307 |
+
" for d in descriptions:\n",
|
| 1308 |
+
" cleaned = allowed_pattern.sub('', d).strip()\n",
|
| 1309 |
+
" if cleaned:\n",
|
| 1310 |
+
" cleaned_descriptions.append(cleaned)\n",
|
| 1311 |
+
"\n",
|
| 1312 |
+
" # Chunk into maximum of 300 descriptions\n",
|
| 1313 |
+
" chunk_size = 300\n",
|
| 1314 |
+
" for idx, i in enumerate(range(0, len(cleaned_descriptions), chunk_size)):\n",
|
| 1315 |
+
" chunk = cleaned_descriptions[i:i + chunk_size]\n",
|
| 1316 |
+
" formatted_content = \"{\" + \"|\".join(chunk) + \"}\"\n",
|
| 1317 |
+
"\n",
|
| 1318 |
+
" # File name starts with rating, then character name, no hashcode\n",
|
| 1319 |
+
" txt_filename = f\"{col}_{char_name}_part{idx+1}.txt\"\n",
|
| 1320 |
+
" txt_filepath = os.path.join(temp_char_dir, txt_filename)\n",
|
| 1321 |
+
"\n",
|
| 1322 |
+
" with open(txt_filepath, \"w\", encoding=\"utf-8\") as f:\n",
|
| 1323 |
+
" f.write(formatted_content)\n",
|
| 1324 |
+
" txt_files_created.append(txt_filepath)\n",
|
| 1325 |
+
"\n",
|
| 1326 |
+
" if txt_files_created:\n",
|
| 1327 |
+
" # Create zip file for this character and upload directly to Drive\n",
|
| 1328 |
+
" zip_filename = f\"{char_name}.zip\"\n",
|
| 1329 |
+
" zip_filepath = os.path.join(drive_output_dir, zip_filename)\n",
|
| 1330 |
+
"\n",
|
| 1331 |
+
" with zipfile.ZipFile(zip_filepath, 'w', zipfile.ZIP_DEFLATED) as zipf:\n",
|
| 1332 |
+
" for file in txt_files_created:\n",
|
| 1333 |
+
" zipf.write(file, os.path.basename(file))\n",
|
| 1334 |
+
"\n",
|
| 1335 |
+
" print(f\"Created and saved to Drive: {zip_filepath} ({len(txt_files_created)} text files)\")\n",
|
| 1336 |
+
"\n",
|
| 1337 |
+
" # Clean up temporary directory\n",
|
| 1338 |
+
" shutil.rmtree(temp_char_dir)\n",
|
| 1339 |
+
"\n",
|
| 1340 |
+
"print(\"\\nAll characters processed successfully!\")"
|
| 1341 |
+
],
|
| 1342 |
+
"execution_count": null,
|
| 1343 |
+
"outputs": [
|
| 1344 |
+
{
|
| 1345 |
+
"output_type": "stream",
|
| 1346 |
+
"name": "stdout",
|
| 1347 |
+
"text": [
|
| 1348 |
+
"Processing: callie__splatoon\n",
|
| 1349 |
+
"Created and saved to Drive: /content/drive/MyDrive/characters/callie__splatoon.zip (9 text files)\n",
|
| 1350 |
+
"Processing: coco_bandicoot\n",
|
| 1351 |
+
"Created and saved to Drive: /content/drive/MyDrive/characters/coco_bandicoot.zip (42 text files)\n",
|
| 1352 |
+
"Processing: holo__spice_and_wolf\n",
|
| 1353 |
+
"Created and saved to Drive: /content/drive/MyDrive/characters/holo__spice_and_wolf.zip (5 text files)\n",
|
| 1354 |
+
"Processing: loona__helluva_boss\n"
|
| 1355 |
+
]
|
| 1356 |
+
}
|
| 1357 |
+
]
|
| 1358 |
}
|
| 1359 |
]
|
| 1360 |
}
|