dansbecker
commited on
Commit
·
a5d5eb6
1
Parent(s):
b8f3f5e
minor cleanup
Browse files
.ipynb_checkpoints/hn_hiring_posts-checkpoint.ipynb
DELETED
@@ -1,101 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "code",
|
5 |
-
"execution_count": 1,
|
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 |
-
"\n",
|
23 |
-
"# There's a mix of HTML, sanitized links and raw Unicode that we'd like to clean up\n",
|
24 |
-
"df.text = df.text.str.replace('<p>', '\\n')\n",
|
25 |
-
"strings_to_remove = ['rel=\"nofollow\"', '<pre>', '</pre>', '<i>', '</i>', '<code>', '</code>', '>']\n",
|
26 |
-
"email_regex = '[a-zA-Z0-9._-]{0,30}@[a-zA-Z0-9._-]{0,20}\\.[a-zA-Z0-9_-]{2,3}' # for redacting emails\n",
|
27 |
-
"munged_url_regex = 'http(s)?:\\&\\#.*?\\<\\/a>'\n",
|
28 |
-
"\n",
|
29 |
-
"for string in strings_to_remove:\n",
|
30 |
-
" df.text = df.text.str.replace(string, '')\n",
|
31 |
-
"\n",
|
32 |
-
"\n",
|
33 |
-
"df.text = df.text.replace(email_regex, 'REDACTED_EMAIL', regex=True)\n",
|
34 |
-
"df.text = df.text.replace(munged_url_regex, '', regex=True)\n",
|
35 |
-
"\n",
|
36 |
-
" # fix some unicode issues\n",
|
37 |
-
"df.text = df.text.str.replace(''', \"'\")\n",
|
38 |
-
"df.text = df.text.str.replace('/', \"/\")\n",
|
39 |
-
"df.text = df.text.str.replace(\""\", '\"')\n",
|
40 |
-
"\n",
|
41 |
-
"hiring_df = df[df.ParentTitle.str.lower().str.contains('who is hiring')]\n",
|
42 |
-
"wants_to_be_hired_df = df[df.ParentTitle.str.lower().str.contains('wants to be hired')]\n",
|
43 |
-
"freelancer_df = df[df.ParentTitle.str.lower().str.contains('freelancer')]\n"
|
44 |
-
]
|
45 |
-
},
|
46 |
-
{
|
47 |
-
"cell_type": "code",
|
48 |
-
"execution_count": 2,
|
49 |
-
"id": "57ca7c96-d94c-4e65-8113-da7729558247",
|
50 |
-
"metadata": {},
|
51 |
-
"outputs": [
|
52 |
-
{
|
53 |
-
"name": "stderr",
|
54 |
-
"output_type": "stream",
|
55 |
-
"text": [
|
56 |
-
"/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"
|
57 |
-
]
|
58 |
-
}
|
59 |
-
],
|
60 |
-
"source": [
|
61 |
-
"import datasets\n",
|
62 |
-
"from huggingface_hub import create_repo\n",
|
63 |
-
"from huggingface_hub import Repository\n",
|
64 |
-
"\n",
|
65 |
-
"all_datasets = datasets.dataset_dict.DatasetDict({'hiring': datasets.Dataset.from_pandas(hiring_df).remove_columns('__index_level_0__'),\n",
|
66 |
-
" 'wants_to_be_hired': datasets.Dataset.from_pandas(wants_to_be_hired_df).remove_columns('__index_level_0__'),\n",
|
67 |
-
" 'freelancer': datasets.Dataset.from_pandas(freelancer_df).remove_columns('__index_level_0__')})\n",
|
68 |
-
"data_path = './data'\n",
|
69 |
-
"all_datasets.save_to_disk(data_path)\n",
|
70 |
-
"\n",
|
71 |
-
"repo_url = 'https://huggingface.co/datasets/dansbecker/hackernews_hiring_posts'\n",
|
72 |
-
"repo = Repository(local_dir=\".\", clone_from=repo_url)\n",
|
73 |
-
"repo.git_add(data_path)\n",
|
74 |
-
"repo.git_add('*.ipynb')\n",
|
75 |
-
"repo.git_add('README.md')\n",
|
76 |
-
"repo.git_commit(\"Add README\")"
|
77 |
-
]
|
78 |
-
}
|
79 |
-
],
|
80 |
-
"metadata": {
|
81 |
-
"kernelspec": {
|
82 |
-
"display_name": "Python 3",
|
83 |
-
"language": "python",
|
84 |
-
"name": "python3"
|
85 |
-
},
|
86 |
-
"language_info": {
|
87 |
-
"codemirror_mode": {
|
88 |
-
"name": "ipython",
|
89 |
-
"version": 3
|
90 |
-
},
|
91 |
-
"file_extension": ".py",
|
92 |
-
"mimetype": "text/x-python",
|
93 |
-
"name": "python",
|
94 |
-
"nbconvert_exporter": "python",
|
95 |
-
"pygments_lexer": "ipython3",
|
96 |
-
"version": "3.8.8"
|
97 |
-
}
|
98 |
-
},
|
99 |
-
"nbformat": 4,
|
100 |
-
"nbformat_minor": 5
|
101 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|