{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":35332,"databundleVersionId":3723648,"sourceType":"competition"}],"dockerImageVersionId":30822,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!ls /kaggle/working","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-27T13:58:42.355892Z","iopub.execute_input":"2024-12-27T13:58:42.356243Z","iopub.status.idle":"2024-12-27T13:58:42.480552Z","shell.execute_reply.started":"2024-12-27T13:58:42.356217Z","shell.execute_reply":"2024-12-27T13:58:42.479190Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\n\n# Define the input file path and output file path\ninput_file = '/kaggle/input/amex-default-prediction/train_data.csv'\noutput_path = 'top_10000_rows.csv'\n\n# Initialize an empty list to collect chunks\nchunk_size = 10000  # Number of rows per chunk\n\n# Process only the first chunk to get the top 10,000 rows\nfor chunk in pd.read_csv(input_file, chunksize=chunk_size):\n    top_10000 = chunk\n    break  # Stop after the first chunk\n\n# Save the top 10,000 rows to a new CSV file\ntop_10000.to_csv(output_path, index=False)\n\nprint(f\"The top 10,000 rows have been saved to {output_path}.\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T13:58:18.481847Z","iopub.execute_input":"2024-12-27T13:58:18.482193Z","iopub.status.idle":"2024-12-27T13:58:22.132813Z","shell.execute_reply.started":"2024-12-27T13:58:18.482168Z","shell.execute_reply":"2024-12-27T13:58:22.131628Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import shutil\n\n# File to compress\nfile_path = '/kaggle/working/top_10000_rows.csv'\nzip_path = '/kaggle/working/top_10000_rows.zip'\n\n# Compress the file\nshutil.make_archive(zip_path.replace('.zip', ''), 'zip', '/kaggle/working', 'top_10000_rows.csv')\nprint(f\"File compressed and saved as: {zip_path}\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T14:00:12.671060Z","iopub.execute_input":"2024-12-27T14:00:12.671453Z","iopub.status.idle":"2024-12-27T14:00:15.415949Z","shell.execute_reply.started":"2024-12-27T14:00:12.671427Z","shell.execute_reply":"2024-12-27T14:00:15.414846Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from IPython.display import FileLink\n\n# Generate a download link\ndownload_link = FileLink(zip_path)\ndisplay(download_link)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T14:00:35.513207Z","iopub.execute_input":"2024-12-27T14:00:35.513655Z","iopub.status.idle":"2024-12-27T14:00:35.521159Z","shell.execute_reply.started":"2024-12-27T14:00:35.513618Z","shell.execute_reply":"2024-12-27T14:00:35.520303Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import shutil\n\n# File to compress and prepare for download\nfile_path = '/kaggle/working/top_10000_rows.csv'\nzip_path = '/kaggle/working/top_10000_rows.zip'\n\n# Compress the file into a ZIP archive\nshutil.make_archive(zip_path.replace('.zip', ''), 'zip', '/kaggle/working', 'top_10000_rows.csv')\n\n# Display a download link\nfrom IPython.display import FileLink\ndownload_link = FileLink(zip_path)\nprint(\"Click the link below to download the file:\")\ndisplay(download_link)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-27T14:01:56.722749Z","iopub.execute_input":"2024-12-27T14:01:56.723137Z","iopub.status.idle":"2024-12-27T14:01:59.519190Z","shell.execute_reply.started":"2024-12-27T14:01:56.723107Z","shell.execute_reply":"2024-12-27T14:01:59.518107Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}