File size: 1,829 Bytes
eab9784
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "id": "SFEUqifXS0At"
      },
      "outputs": [
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Processing CSV files: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 16573/16573 [01:14<00:00, 222.34it/s]\n"
          ]
        }
      ],
      "source": [
        "import os\n",
        "import pandas as pd\n",
        "from tqdm import tqdm\n",
        "\n",
        "# Create an empty DataFrame\n",
        "df = pd.DataFrame()\n",
        "df['context'] = None\n",
        "df['answer'] = None\n",
        "\n",
        "# Read all CSV files from the folder 'all_csv'\n",
        "folder_path = 'all_csv'  # Path to the folder containing CSV files\n",
        "paths = [os.path.join(folder_path, filename) for filename in os.listdir(folder_path) if filename.endswith('.csv')]\n",
        "for i, path in enumerate(tqdm(paths, desc=\"Processing CSV files\")):\n",
        "    data = pd.read_csv(path, sep='#')\n",
        "    df.loc[i, 'context'] = data.to_string()\n",
        "    df.loc[i, 'answer'] = data.to_json(force_ascii=False)\n",
        "\n",
        "# Write the DataFrame to a CSV file\n",
        "df.to_csv('table_extract.csv', index=False)"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.10.4"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}