File size: 3,510 Bytes
38f47f6
 
 
 
b879b12
38f47f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b879b12
 
 
38f47f6
 
b879b12
38f47f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b879b12
 
38f47f6
 
 
 
 
b879b12
 
 
 
 
38f47f6
 
 
 
 
 
b879b12
 
 
38f47f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "056aa255-fda1-4cde-be24-459f6ad2c8b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/anaconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py:3165: DtypeWarning: Columns (4) have mixed types.Specify dtype option on import or set low_memory=False.\n",
      "  has_raised = await self.run_ast_nodes(code_ast.body, cell_name,\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv('raw/bq-results-20211206-133858-irtkgx60el7i.csv').drop(['ParentUrl', 'ParentAuthor', 'ParentTime', 'ParentScore'], axis=1)\n",
    "\n",
    "# There's a mix of HTML, sanitized links and raw Unicode that we'd like to clean up\n",
    "df.text = df.text.str.replace('<p>', '\\n')\n",
    "strings_to_remove = ['rel=\"nofollow\"', '<pre>', '</pre>', '<i>', '</i>', '<code>', '</code>', '&gt;']\n",
    "email_regex = '[a-zA-Z0-9._-]{0,30}@[a-zA-Z0-9._-]{0,20}\\.[a-zA-Z0-9_-]{2,3}' # for redacting emails\n",
    "munged_url_regex = 'http(s)?:\\&\\#.*?\\<\\/a>'\n",
    "\n",
    "for string in strings_to_remove:\n",
    "    df.text = df.text.str.replace(string, '')\n",
    "\n",
    "\n",
    "df.text = df.text.replace(email_regex, 'REDACTED_EMAIL', regex=True)\n",
    "df.text = df.text.replace(munged_url_regex, '', regex=True)\n",
    "\n",
    "    # fix some unicode issues\n",
    "df.text = df.text.str.replace('&#x27;', \"'\")\n",
    "df.text = df.text.str.replace('&#x2F;', \"/\")\n",
    "df.text = df.text.str.replace(\"&quot;\", '\"')\n",
    "\n",
    "hiring_df = df[df.ParentTitle.str.lower().str.contains('who is hiring')]\n",
    "wants_to_be_hired_df = df[df.ParentTitle.str.lower().str.contains('wants to be hired')]\n",
    "freelancer_df = df[df.ParentTitle.str.lower().str.contains('freelancer')]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "57ca7c96-d94c-4e65-8113-da7729558247",
   "metadata": {},
   "outputs": [],
   "source": [
    "import datasets\n",
    "from huggingface_hub import create_repo\n",
    "from huggingface_hub import Repository\n",
    "\n",
    "all_datasets = datasets.dataset_dict.DatasetDict({'hiring': datasets.Dataset.from_pandas(hiring_df).remove_columns('__index_level_0__'),\n",
    "                                                  'wants_to_be_hired': datasets.Dataset.from_pandas(wants_to_be_hired_df).remove_columns('__index_level_0__'),\n",
    "                                                  'freelancer': datasets.Dataset.from_pandas(freelancer_df).remove_columns('__index_level_0__')})\n",
    "data_path = './data'\n",
    "all_datasets.save_to_disk(data_path)\n",
    "\n",
    "repo_url = 'https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts'\n",
    "repo = Repository(local_dir=\".\", clone_from=repo_url)\n",
    "repo.git_add(data_path)\n",
    "repo.git_add('*.ipynb')\n",
    "repo.git_add('README.md')\n",
    "repo.git_commit(\"A standard update\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "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.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}