dansbecker
commited on
Commit
•
38f47f6
1
Parent(s):
6f68ddf
Add noteook that cleans and pushes data
Browse files
.ipynb_checkpoints/hn_hiring_posts-checkpoint.ipynb
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 4,
|
6 |
+
"id": "056aa255-fda1-4cde-be24-459f6ad2c8b9",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stderr",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"/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",
|
14 |
+
" has_raised = await self.run_ast_nodes(code_ast.body, cell_name,\n"
|
15 |
+
]
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"source": [
|
19 |
+
"import pandas as pd\n",
|
20 |
+
"from bs4 import BeautifulSoup\n",
|
21 |
+
"\n",
|
22 |
+
"df = pd.read_csv('./bq-results-20211206-133858-irtkgx60el7i.csv').drop(['ParentUrl', 'ParentAuthor', 'ParentTime', 'ParentScore'], axis=1)\n",
|
23 |
+
"df.text = df.text.str.replace('<p>', '\\n')\n",
|
24 |
+
"strings_to_remove = ['rel=\"nofollow\"', '<pre>', '</pre>', '<i>', '</i>', '<code>', '</code>', '>']\n",
|
25 |
+
"email_regex = '[a-zA-Z0-9._-]{0,30}@[a-zA-Z0-9._-]{0,20}\\.[a-zA-Z0-9_-]{2,3}'\n",
|
26 |
+
"munged_url_regex = 'http(s)?:\\&\\#.*?\\<\\/a>'\n",
|
27 |
+
"\n",
|
28 |
+
"for string in strings_to_remove:\n",
|
29 |
+
" df.text = df.text.str.replace(string, '')\n",
|
30 |
+
"\n",
|
31 |
+
"\n",
|
32 |
+
"df.text = df.text.replace(email_regex, 'REDACTED_EMAIL', regex=True)\n",
|
33 |
+
"df.text = df.text.replace(munged_url_regex, '', regex=True)\n",
|
34 |
+
"\n",
|
35 |
+
" # fix some unicode issues\n",
|
36 |
+
"df.text = df.text.str.replace(''', \"'\")\n",
|
37 |
+
"df.text = df.text.str.replace('/', \"/\")\n",
|
38 |
+
"df.text = df.text.str.replace(\""\", '\"')\n",
|
39 |
+
"\n",
|
40 |
+
"hiring_df = df[df.ParentTitle.str.lower().str.contains('who is hiring')]\n",
|
41 |
+
"wants_to_be_hired_df = df[df.ParentTitle.str.lower().str.contains('wants to be hired')]\n",
|
42 |
+
"freelancer_df = df[df.ParentTitle.str.lower().str.contains('freelancer')]\n"
|
43 |
+
]
|
44 |
+
},
|
45 |
+
{
|
46 |
+
"cell_type": "code",
|
47 |
+
"execution_count": 24,
|
48 |
+
"id": "1ee19b74-2085-40d8-b9d2-51b526f4d438",
|
49 |
+
"metadata": {},
|
50 |
+
"outputs": [],
|
51 |
+
"source": [
|
52 |
+
"import datasets\n",
|
53 |
+
"from huggingface_hub import create_repo\n",
|
54 |
+
"from huggingface_hub import Repository"
|
55 |
+
]
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"cell_type": "code",
|
59 |
+
"execution_count": 43,
|
60 |
+
"id": "57ca7c96-d94c-4e65-8113-da7729558247",
|
61 |
+
"metadata": {},
|
62 |
+
"outputs": [
|
63 |
+
{
|
64 |
+
"name": "stderr",
|
65 |
+
"output_type": "stream",
|
66 |
+
"text": [
|
67 |
+
"/Users/dan.becker/Desktop/hackernews_hiring_dataset is already a clone of https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts. Make sure you pull the latest changes with `repo.git_pull()`.\n"
|
68 |
+
]
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"ename": "OSError",
|
72 |
+
"evalue": "fatal: pathspec 'hackernews_hiring_dataset/data/*' did not match any files\n",
|
73 |
+
"output_type": "error",
|
74 |
+
"traceback": [
|
75 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
76 |
+
"\u001b[0;31mCalledProcessError\u001b[0m Traceback (most recent call last)",
|
77 |
+
"\u001b[0;32m/usr/local/anaconda3/lib/python3.8/site-packages/huggingface_hub/repository.py\u001b[0m in \u001b[0;36mgit_add\u001b[0;34m(self, pattern, auto_lfs_track)\u001b[0m\n\u001b[1;32m 908\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 909\u001b[0;31m result = subprocess.run(\n\u001b[0m\u001b[1;32m 910\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m\"git\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"add\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"-v\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpattern\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
78 |
+
"\u001b[0;32m/usr/local/anaconda3/lib/python3.8/subprocess.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(input, capture_output, timeout, check, *popenargs, **kwargs)\u001b[0m\n\u001b[1;32m 515\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcheck\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mretcode\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 516\u001b[0;31m raise CalledProcessError(retcode, process.args,\n\u001b[0m\u001b[1;32m 517\u001b[0m output=stdout, stderr=stderr)\n",
|
79 |
+
"\u001b[0;31mCalledProcessError\u001b[0m: Command '['git', 'add', '-v', 'hackernews_hiring_dataset/data/*']' returned non-zero exit status 128.",
|
80 |
+
"\nDuring handling of the above exception, another exception occurred:\n",
|
81 |
+
"\u001b[0;31mOSError\u001b[0m Traceback (most recent call last)",
|
82 |
+
"\u001b[0;32m<ipython-input-43-bd751bbd86f5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mrepo_url\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mrepo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mRepository\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlocal_dir\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"hackernews_hiring_dataset\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mclone_from\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrepo_url\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m \u001b[0mrepo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgit_add\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata_path\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m'/*'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 10\u001b[0m \u001b[0mrepo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgit_commit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Push data from notebook\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
83 |
+
"\u001b[0;32m/usr/local/anaconda3/lib/python3.8/site-packages/huggingface_hub/repository.py\u001b[0m in \u001b[0;36mgit_add\u001b[0;34m(self, pattern, auto_lfs_track)\u001b[0m\n\u001b[1;32m 917\u001b[0m \u001b[0mlogger\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minfo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"Adding to index:\\n{result.stdout}\\n\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 918\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0msubprocess\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCalledProcessError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 919\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mEnvironmentError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mexc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstderr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 920\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 921\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mgit_commit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcommit_message\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"commit files to HF hub\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
84 |
+
"\u001b[0;31mOSError\u001b[0m: fatal: pathspec 'hackernews_hiring_dataset/data/*' did not match any files\n"
|
85 |
+
]
|
86 |
+
}
|
87 |
+
],
|
88 |
+
"source": [
|
89 |
+
"all_datasets = datasets.dataset_dict.DatasetDict({'hiring': datasets.Dataset.from_pandas(hiring_df),\n",
|
90 |
+
" 'wants_to_be_hired': datasets.Dataset.from_pandas(wants_to_be_hired_df),\n",
|
91 |
+
" 'freelancer': datasets.Dataset.from_pandas(freelancer_df)})\n",
|
92 |
+
"data_path = './data'\n",
|
93 |
+
"all_datasets.save_to_disk(data_path)\n",
|
94 |
+
"\n",
|
95 |
+
"repo_url = 'https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts'\n",
|
96 |
+
"repo = Repository(local_dir=\".\", clone_from=repo_url)\n",
|
97 |
+
"repo.git_pull()\n",
|
98 |
+
"repo.git_add(data_path)\n",
|
99 |
+
"repo.git_commit(\"Push data from notebook\")"
|
100 |
+
]
|
101 |
+
},
|
102 |
+
{
|
103 |
+
"cell_type": "code",
|
104 |
+
"execution_count": 36,
|
105 |
+
"id": "2e7fbc2c-550e-4266-b7f2-63287953fdc7",
|
106 |
+
"metadata": {},
|
107 |
+
"outputs": [
|
108 |
+
{
|
109 |
+
"data": {
|
110 |
+
"text/plain": [
|
111 |
+
"\u001b[0;31mSignature:\u001b[0m \u001b[0mrepo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgit_commit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcommit_message\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'commit files to HF hub'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
112 |
+
"\u001b[0;31mDocstring:\u001b[0m git commit\n",
|
113 |
+
"\u001b[0;31mFile:\u001b[0m /usr/local/anaconda3/lib/python3.8/site-packages/huggingface_hub/repository.py\n",
|
114 |
+
"\u001b[0;31mType:\u001b[0m method\n"
|
115 |
+
]
|
116 |
+
},
|
117 |
+
"metadata": {},
|
118 |
+
"output_type": "display_data"
|
119 |
+
}
|
120 |
+
],
|
121 |
+
"source": [
|
122 |
+
"repo.git_commit?"
|
123 |
+
]
|
124 |
+
},
|
125 |
+
{
|
126 |
+
"cell_type": "code",
|
127 |
+
"execution_count": 23,
|
128 |
+
"id": "1421d124-a4ae-401e-9753-27a82e9f35d4",
|
129 |
+
"metadata": {},
|
130 |
+
"outputs": [
|
131 |
+
{
|
132 |
+
"ename": "TypeError",
|
133 |
+
"evalue": "Expected a pyarrow.Table or a datasets.table.Table object, but got {'hiring': text \\\n0 Kindling -- New York City\\nLead Application De... \n1 Angular UI Developers: Help Improve the State ... \n2 Cir.cl is a funded startup founded by former O... \n3 Backplane - Palo Alto, CA\\n== About Us ==\\nWe ... \n5 We are building supercomputers and bespoke sof... \n... ... \n111574 LOCATION: Mountain View, CA |Full-time |ONSITE... \n111575 Eaze | Senior Software Engineer | San Francisc... \n111576 Auckland, New Zealand | REMOTE | VISA\\n---\\n# ... \n111577 Elementum | Mountain View | Onsite\\nI am the H... \n111578 SeatGeek — New York, NY — Full Time — We're a ... \n\n CommentTime CommentAuthor \\\n0 2014-08-01 16:15:39 UTC toestues \n1 2014-08-01 16:15:52 UTC AngularJobs \n2 2014-05-01 20:50:30 UTC cld276 \n3 2014-05-01 20:50:39 UTC chengyinliu \n5 2013-04-01 19:24:46 UTC kaib \n... ... ... \n111574 2017-07-03 23:46:02 UTC katrinadurant \n111575 2017-07-03 21:05:44 UTC spade \n111576 2017-07-03 21:05:39 UTC neftaly \n111577 2017-07-04 03:16:13 UTC sv13 \n111578 2017-07-04 13:05:00 UTC jack7890 \n\n ParentTitle \n0 Ask HN: Who is hiring? (August 2014) \n1 Ask HN: Who is hiring? (August 2014) \n2 Ask HN: Who is hiring? (May 2014) \n3 Ask HN: Who is hiring? (May 2014) \n5 Ask HN: Who is hiring? (April 2013) \n... ... \n111574 Ask HN: Who is hiring? (July 2017) \n111575 Ask HN: Who is hiring? (July 2017) \n111576 Ask HN: Who is hiring? (July 2017) \n111577 Ask HN: Who is hiring? (July 2017) \n111578 Ask HN: Who is hiring? (July 2017) \n\n[75974 rows x 4 columns], 'wants_to_be_hired': text \\\n7 Location: FL\\n Remote:Yes, Part time preferred... \n8 Willing to relocate: No\\nLocation: London, UK\\... \n10 Location: Ukraine\\nRemote: Yes\\nWilling to rel... \n11 Location: London\\nRemote: No\\nWilling to reloc... \n23 Location: India\\nRemote: Yes\\nTechnologies: Py... \n... ... \n111535 Location: Montreal, Quebec (Canada)\\nRemote: N... \n111542 Location: Seattle, WA\\nRemote: yes/exclusively... \n111543 Location: India\\nRemote: Yes\\nWilling to reloc... \n111562 Hi, I am Sagar Ghai, a recent Computer Science... \n111568 Location: Baltimore, Delaware\\nRemote: Preferr... \n\n CommentTime CommentAuthor \\\n7 2019-12-03 14:53:37 UTC kanagac \n8 2021-09-01 16:29:21 UTC electronstudio \n10 2014-11-01 21:46:49 UTC andrey_utkin \n11 2014-09-02 21:26:34 UTC mikemases \n23 2021-06-02 02:40:37 UTC kgritesh \n... ... ... \n111535 2017-07-05 18:12:05 UTC ajgaba \n111542 2017-07-03 16:33:10 UTC fuzzy-logic \n111543 2017-07-04 16:17:41 UTC kshk123 \n111562 2017-07-04 08:34:09 UTC sagarghai \n111568 2017-07-05 21:33:02 UTC wernercd \n\n ParentTitle \n7 Ask HN: Who wants to be hired? (December 2019) \n8 Ask HN: Who wants to be hired? (September 2021) \n10 Ask HN: Who wants to be hired? (November 2014) \n11 Ask HN: Who wants to be hired? (September 2014) \n23 Ask HN: Who wants to be hired? (June 2021) \n... ... \n111535 Ask HN: Who wants to be hired? (July 2017) \n111542 Ask HN: Who wants to be hired? (July 2017) \n111543 Ask HN: Who wants to be hired? (July 2017) \n111562 Ask HN: Who wants to be hired? (July 2017) \n111568 Ask HN: Who wants to be hired? (July 2017) \n\n[20262 rows x 4 columns], 'freelancer': text \\\n4 SEEKING WORK\\nLocation: Victoria, B.C.\\nRemote... \n6 SEEKING WORK, Nottingham UK, Remote\\nLAMP (Per... \n12 SEEKING WORK | GMT+8 (Perth, Australia) | Remo... \n15 SEEKING WORK | REMOTE SR Software Architect / ... \n16 SEEKING WORK\\nZoë Davidson // Front End Engine... \n... ... \n111518 SEEKING WORK - Toronto + REMOTE (GMT-5).\\nFull... \n111523 SEEKING WORK - Remote, Berlin\\nContent Marketi... \n111538 SEEKING WORK - Northern Utah (SLC to Provo) or... \n111547 SEEKING WORK - US, Remote\\n- Available mid-Aug... \n111572 SEEKING WORK - Remote - Brisbane, Australia\\nB... \n\n CommentTime CommentAuthor \\\n4 2015-04-01 16:39:38 UTC spitfire \n6 2012-02-01 14:05:14 UTC mike-cardwell \n12 2021-11-01 15:09:57 UTC bengtan \n15 2021-11-01 15:40:58 UTC jhoelzel \n16 2021-11-01 15:41:14 UTC zdavidson4 \n... ... ... \n111518 2017-07-03 16:03:57 UTC d10p \n111523 2017-07-04 07:37:22 UTC rwieruch \n111538 2017-07-08 06:42:31 UTC VaedaStrike \n111547 2017-07-14 19:17:40 UTC jeffmk \n111572 2017-07-04 04:11:32 UTC pirhoteknik \n\n ParentTitle \n4 Ask HN: Freelancer? Seeking freelancer? (April... \n6 Ask HN: Freelancer? Seeking freelancer? (Febr... \n12 Ask HN: Freelancer? Seeking freelancer? (Novem... \n15 Ask HN: Freelancer? Seeking freelancer? (Novem... \n16 Ask HN: Freelancer? Seeking freelancer? (Novem... \n... ... \n111518 Ask HN: Freelancer? Seeking freelancer? (July ... \n111523 Ask HN: Freelancer? Seeking freelancer? (July ... \n111538 Ask HN: Freelancer? Seeking freelancer? (July ... \n111547 Ask HN: Freelancer? Seeking freelancer? (July ... \n111572 Ask HN: Freelancer? Seeking freelancer? (July ... \n\n[15266 rows x 4 columns]}.",
|
134 |
+
"output_type": "error",
|
135 |
+
"traceback": [
|
136 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
137 |
+
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
|
138 |
+
"\u001b[0;32m<ipython-input-23-d01447c6056e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m datasets.Dataset({'hiring': hiring_df,\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m'wants_to_be_hired'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mwants_to_be_hired_df\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m 'freelancer': freelancer_df})\n",
|
139 |
+
"\u001b[0;32m/usr/local/anaconda3/lib/python3.8/site-packages/datasets/arrow_dataset.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, arrow_table, info, split, indices_table, fingerprint)\u001b[0m\n\u001b[1;32m 580\u001b[0m \u001b[0mIndexableMixin\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 581\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 582\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_data\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mTable\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_check_table\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marrow_table\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 583\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_indices\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mTable\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_check_table\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindices_table\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mindices_table\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 584\u001b[0m \u001b[0mmaybe_register_dataset_for_temp_dir_deletion\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
140 |
+
"\u001b[0;32m/usr/local/anaconda3/lib/python3.8/site-packages/datasets/arrow_dataset.py\u001b[0m in \u001b[0;36m_check_table\u001b[0;34m(table)\u001b[0m\n\u001b[1;32m 556\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtable\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 557\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 558\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"Expected a pyarrow.Table or a datasets.table.Table object, but got {table}.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 559\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 560\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
141 |
+
"\u001b[0;31mTypeError\u001b[0m: Expected a pyarrow.Table or a datasets.table.Table object, but got {'hiring': text \\\n0 Kindling -- New York City\\nLead Application De... \n1 Angular UI Developers: Help Improve the State ... \n2 Cir.cl is a funded startup founded by former O... \n3 Backplane - Palo Alto, CA\\n== About Us ==\\nWe ... \n5 We are building supercomputers and bespoke sof... \n... ... \n111574 LOCATION: Mountain View, CA |Full-time |ONSITE... \n111575 Eaze | Senior Software Engineer | San Francisc... \n111576 Auckland, New Zealand | REMOTE | VISA\\n---\\n# ... \n111577 Elementum | Mountain View | Onsite\\nI am the H... \n111578 SeatGeek — New York, NY — Full Time — We're a ... \n\n CommentTime CommentAuthor \\\n0 2014-08-01 16:15:39 UTC toestues \n1 2014-08-01 16:15:52 UTC AngularJobs \n2 2014-05-01 20:50:30 UTC cld276 \n3 2014-05-01 20:50:39 UTC chengyinliu \n5 2013-04-01 19:24:46 UTC kaib \n... ... ... \n111574 2017-07-03 23:46:02 UTC katrinadurant \n111575 2017-07-03 21:05:44 UTC spade \n111576 2017-07-03 21:05:39 UTC neftaly \n111577 2017-07-04 03:16:13 UTC sv13 \n111578 2017-07-04 13:05:00 UTC jack7890 \n\n ParentTitle \n0 Ask HN: Who is hiring? (August 2014) \n1 Ask HN: Who is hiring? (August 2014) \n2 Ask HN: Who is hiring? (May 2014) \n3 Ask HN: Who is hiring? (May 2014) \n5 Ask HN: Who is hiring? (April 2013) \n... ... \n111574 Ask HN: Who is hiring? (July 2017) \n111575 Ask HN: Who is hiring? (July 2017) \n111576 Ask HN: Who is hiring? (July 2017) \n111577 Ask HN: Who is hiring? (July 2017) \n111578 Ask HN: Who is hiring? (July 2017) \n\n[75974 rows x 4 columns], 'wants_to_be_hired': text \\\n7 Location: FL\\n Remote:Yes, Part time preferred... \n8 Willing to relocate: No\\nLocation: London, UK\\... \n10 Location: Ukraine\\nRemote: Yes\\nWilling to rel... \n11 Location: London\\nRemote: No\\nWilling to reloc... \n23 Location: India\\nRemote: Yes\\nTechnologies: Py... \n... ... \n111535 Location: Montreal, Quebec (Canada)\\nRemote: N... \n111542 Location: Seattle, WA\\nRemote: yes/exclusively... \n111543 Location: India\\nRemote: Yes\\nWilling to reloc... \n111562 Hi, I am Sagar Ghai, a recent Computer Science... \n111568 Location: Baltimore, Delaware\\nRemote: Preferr... \n\n CommentTime CommentAuthor \\\n7 2019-12-03 14:53:37 UTC kanagac \n8 2021-09-01 16:29:21 UTC electronstudio \n10 2014-11-01 21:46:49 UTC andrey_utkin \n11 2014-09-02 21:26:34 UTC mikemases \n23 2021-06-02 02:40:37 UTC kgritesh \n... ... ... \n111535 2017-07-05 18:12:05 UTC ajgaba \n111542 2017-07-03 16:33:10 UTC fuzzy-logic \n111543 2017-07-04 16:17:41 UTC kshk123 \n111562 2017-07-04 08:34:09 UTC sagarghai \n111568 2017-07-05 21:33:02 UTC wernercd \n\n ParentTitle \n7 Ask HN: Who wants to be hired? (December 2019) \n8 Ask HN: Who wants to be hired? (September 2021) \n10 Ask HN: Who wants to be hired? (November 2014) \n11 Ask HN: Who wants to be hired? (September 2014) \n23 Ask HN: Who wants to be hired? (June 2021) \n... ... \n111535 Ask HN: Who wants to be hired? (July 2017) \n111542 Ask HN: Who wants to be hired? (July 2017) \n111543 Ask HN: Who wants to be hired? (July 2017) \n111562 Ask HN: Who wants to be hired? (July 2017) \n111568 Ask HN: Who wants to be hired? (July 2017) \n\n[20262 rows x 4 columns], 'freelancer': text \\\n4 SEEKING WORK\\nLocation: Victoria, B.C.\\nRemote... \n6 SEEKING WORK, Nottingham UK, Remote\\nLAMP (Per... \n12 SEEKING WORK | GMT+8 (Perth, Australia) | Remo... \n15 SEEKING WORK | REMOTE SR Software Architect / ... \n16 SEEKING WORK\\nZoë Davidson // Front End Engine... \n... ... \n111518 SEEKING WORK - Toronto + REMOTE (GMT-5).\\nFull... \n111523 SEEKING WORK - Remote, Berlin\\nContent Marketi... \n111538 SEEKING WORK - Northern Utah (SLC to Provo) or... \n111547 SEEKING WORK - US, Remote\\n- Available mid-Aug... \n111572 SEEKING WORK - Remote - Brisbane, Australia\\nB... \n\n CommentTime CommentAuthor \\\n4 2015-04-01 16:39:38 UTC spitfire \n6 2012-02-01 14:05:14 UTC mike-cardwell \n12 2021-11-01 15:09:57 UTC bengtan \n15 2021-11-01 15:40:58 UTC jhoelzel \n16 2021-11-01 15:41:14 UTC zdavidson4 \n... ... ... \n111518 2017-07-03 16:03:57 UTC d10p \n111523 2017-07-04 07:37:22 UTC rwieruch \n111538 2017-07-08 06:42:31 UTC VaedaStrike \n111547 2017-07-14 19:17:40 UTC jeffmk \n111572 2017-07-04 04:11:32 UTC pirhoteknik \n\n ParentTitle \n4 Ask HN: Freelancer? Seeking freelancer? (April... \n6 Ask HN: Freelancer? Seeking freelancer? (Febr... \n12 Ask HN: Freelancer? Seeking freelancer? (Novem... \n15 Ask HN: Freelancer? Seeking freelancer? (Novem... \n16 Ask HN: Freelancer? Seeking freelancer? (Novem... \n... ... \n111518 Ask HN: Freelancer? Seeking freelancer? (July ... \n111523 Ask HN: Freelancer? Seeking freelancer? (July ... \n111538 Ask HN: Freelancer? Seeking freelancer? (July ... \n111547 Ask HN: Freelancer? Seeking freelancer? (July ... \n111572 Ask HN: Freelancer? Seeking freelancer? (July ... \n\n[15266 rows x 4 columns]}."
|
142 |
+
]
|
143 |
+
}
|
144 |
+
],
|
145 |
+
"source": []
|
146 |
+
},
|
147 |
+
{
|
148 |
+
"cell_type": "code",
|
149 |
+
"execution_count": null,
|
150 |
+
"id": "eea7788b-8919-4fb9-bec4-9a349ee34728",
|
151 |
+
"metadata": {},
|
152 |
+
"outputs": [],
|
153 |
+
"source": []
|
154 |
+
}
|
155 |
+
],
|
156 |
+
"metadata": {
|
157 |
+
"kernelspec": {
|
158 |
+
"display_name": "Python 3",
|
159 |
+
"language": "python",
|
160 |
+
"name": "python3"
|
161 |
+
},
|
162 |
+
"language_info": {
|
163 |
+
"codemirror_mode": {
|
164 |
+
"name": "ipython",
|
165 |
+
"version": 3
|
166 |
+
},
|
167 |
+
"file_extension": ".py",
|
168 |
+
"mimetype": "text/x-python",
|
169 |
+
"name": "python",
|
170 |
+
"nbconvert_exporter": "python",
|
171 |
+
"pygments_lexer": "ipython3",
|
172 |
+
"version": "3.8.8"
|
173 |
+
}
|
174 |
+
},
|
175 |
+
"nbformat": 4,
|
176 |
+
"nbformat_minor": 5
|
177 |
+
}
|
hn_hiring_posts.ipynb
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 4,
|
6 |
+
"id": "056aa255-fda1-4cde-be24-459f6ad2c8b9",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stderr",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"/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",
|
14 |
+
" has_raised = await self.run_ast_nodes(code_ast.body, cell_name,\n"
|
15 |
+
]
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"source": [
|
19 |
+
"import pandas as pd\n",
|
20 |
+
"\n",
|
21 |
+
"df = pd.read_csv('raw/bq-results-20211206-133858-irtkgx60el7i.csv').drop(['ParentUrl', 'ParentAuthor', 'ParentTime', 'ParentScore'], axis=1)\n",
|
22 |
+
"df.text = df.text.str.replace('<p>', '\\n')\n",
|
23 |
+
"strings_to_remove = ['rel=\"nofollow\"', '<pre>', '</pre>', '<i>', '</i>', '<code>', '</code>', '>']\n",
|
24 |
+
"email_regex = '[a-zA-Z0-9._-]{0,30}@[a-zA-Z0-9._-]{0,20}\\.[a-zA-Z0-9_-]{2,3}'\n",
|
25 |
+
"munged_url_regex = 'http(s)?:\\&\\#.*?\\<\\/a>'\n",
|
26 |
+
"\n",
|
27 |
+
"for string in strings_to_remove:\n",
|
28 |
+
" df.text = df.text.str.replace(string, '')\n",
|
29 |
+
"\n",
|
30 |
+
"\n",
|
31 |
+
"df.text = df.text.replace(email_regex, 'REDACTED_EMAIL', regex=True)\n",
|
32 |
+
"df.text = df.text.replace(munged_url_regex, '', regex=True)\n",
|
33 |
+
"\n",
|
34 |
+
" # fix some unicode issues\n",
|
35 |
+
"df.text = df.text.str.replace(''', \"'\")\n",
|
36 |
+
"df.text = df.text.str.replace('/', \"/\")\n",
|
37 |
+
"df.text = df.text.str.replace(\""\", '\"')\n",
|
38 |
+
"\n",
|
39 |
+
"hiring_df = df[df.ParentTitle.str.lower().str.contains('who is hiring')]\n",
|
40 |
+
"wants_to_be_hired_df = df[df.ParentTitle.str.lower().str.contains('wants to be hired')]\n",
|
41 |
+
"freelancer_df = df[df.ParentTitle.str.lower().str.contains('freelancer')]\n"
|
42 |
+
]
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"cell_type": "code",
|
46 |
+
"execution_count": 5,
|
47 |
+
"id": "57ca7c96-d94c-4e65-8113-da7729558247",
|
48 |
+
"metadata": {},
|
49 |
+
"outputs": [
|
50 |
+
{
|
51 |
+
"name": "stderr",
|
52 |
+
"output_type": "stream",
|
53 |
+
"text": [
|
54 |
+
"/Users/dan.becker/Desktop/hackernews_hiring_dataset/. is already a clone of https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts. Make sure you pull the latest changes with `repo.git_pull()`.\n"
|
55 |
+
]
|
56 |
+
}
|
57 |
+
],
|
58 |
+
"source": [
|
59 |
+
"import datasets\n",
|
60 |
+
"from huggingface_hub import create_repo\n",
|
61 |
+
"from huggingface_hub import Repository\n",
|
62 |
+
"\n",
|
63 |
+
"all_datasets = datasets.dataset_dict.DatasetDict({'hiring': datasets.Dataset.from_pandas(hiring_df),\n",
|
64 |
+
" 'wants_to_be_hired': datasets.Dataset.from_pandas(wants_to_be_hired_df),\n",
|
65 |
+
" 'freelancer': datasets.Dataset.from_pandas(freelancer_df)})\n",
|
66 |
+
"data_path = './data'\n",
|
67 |
+
"all_datasets.save_to_disk(data_path)\n",
|
68 |
+
"\n",
|
69 |
+
"repo_url = 'https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts'\n",
|
70 |
+
"repo = Repository(local_dir=\".\", clone_from=repo_url)\n",
|
71 |
+
"repo.git_add(data_path)\n",
|
72 |
+
"repo.git_commit(\"Push data from notebook\")"
|
73 |
+
]
|
74 |
+
},
|
75 |
+
{
|
76 |
+
"cell_type": "code",
|
77 |
+
"execution_count": 6,
|
78 |
+
"id": "2e7fbc2c-550e-4266-b7f2-63287953fdc7",
|
79 |
+
"metadata": {},
|
80 |
+
"outputs": [
|
81 |
+
{
|
82 |
+
"data": {
|
83 |
+
"application/vnd.jupyter.widget-view+json": {
|
84 |
+
"model_id": "d92654a5fdf7471b8fdf02eedd65fd24",
|
85 |
+
"version_major": 2,
|
86 |
+
"version_minor": 0
|
87 |
+
},
|
88 |
+
"text/plain": [
|
89 |
+
"Upload file data/hiring/dataset.arrow: 0%| | 32.0k/78.8M [00:00<?, ?B/s]"
|
90 |
+
]
|
91 |
+
},
|
92 |
+
"metadata": {},
|
93 |
+
"output_type": "display_data"
|
94 |
+
},
|
95 |
+
{
|
96 |
+
"data": {
|
97 |
+
"application/vnd.jupyter.widget-view+json": {
|
98 |
+
"model_id": "7f86380237d1442a83c03c15ce1a492d",
|
99 |
+
"version_major": 2,
|
100 |
+
"version_minor": 0
|
101 |
+
},
|
102 |
+
"text/plain": [
|
103 |
+
"Upload file data/freelancer/dataset.arrow: 0%| | 32.0k/10.8M [00:00<?, ?B/s]"
|
104 |
+
]
|
105 |
+
},
|
106 |
+
"metadata": {},
|
107 |
+
"output_type": "display_data"
|
108 |
+
},
|
109 |
+
{
|
110 |
+
"data": {
|
111 |
+
"application/vnd.jupyter.widget-view+json": {
|
112 |
+
"model_id": "a15bce1da7ed412ca9359adc53dfa92f",
|
113 |
+
"version_major": 2,
|
114 |
+
"version_minor": 0
|
115 |
+
},
|
116 |
+
"text/plain": [
|
117 |
+
"Upload file data/wants_to_be_hired/dataset.arrow: 0%| | 32.0k/11.0M [00:00<?, ?B/s]"
|
118 |
+
]
|
119 |
+
},
|
120 |
+
"metadata": {},
|
121 |
+
"output_type": "display_data"
|
122 |
+
},
|
123 |
+
{
|
124 |
+
"name": "stderr",
|
125 |
+
"output_type": "stream",
|
126 |
+
"text": [
|
127 |
+
"To https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts\n",
|
128 |
+
" d59d452..6f68ddf main -> main\n",
|
129 |
+
"\n"
|
130 |
+
]
|
131 |
+
},
|
132 |
+
{
|
133 |
+
"data": {
|
134 |
+
"text/plain": [
|
135 |
+
"'https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts/commit/6f68ddf7d649bf6d5892197cce8cd2963559946d'"
|
136 |
+
]
|
137 |
+
},
|
138 |
+
"execution_count": 6,
|
139 |
+
"metadata": {},
|
140 |
+
"output_type": "execute_result"
|
141 |
+
}
|
142 |
+
],
|
143 |
+
"source": [
|
144 |
+
"repo.git_push()"
|
145 |
+
]
|
146 |
+
}
|
147 |
+
],
|
148 |
+
"metadata": {
|
149 |
+
"kernelspec": {
|
150 |
+
"display_name": "Python 3",
|
151 |
+
"language": "python",
|
152 |
+
"name": "python3"
|
153 |
+
},
|
154 |
+
"language_info": {
|
155 |
+
"codemirror_mode": {
|
156 |
+
"name": "ipython",
|
157 |
+
"version": 3
|
158 |
+
},
|
159 |
+
"file_extension": ".py",
|
160 |
+
"mimetype": "text/x-python",
|
161 |
+
"name": "python",
|
162 |
+
"nbconvert_exporter": "python",
|
163 |
+
"pygments_lexer": "ipython3",
|
164 |
+
"version": "3.8.8"
|
165 |
+
}
|
166 |
+
},
|
167 |
+
"nbformat": 4,
|
168 |
+
"nbformat_minor": 5
|
169 |
+
}
|