-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatacollection.py
More file actions
65 lines (51 loc) · 1.74 KB
/
datacollection.py
File metadata and controls
65 lines (51 loc) · 1.74 KB
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
#this script is to call online live data from any source just by mentioning links
from sqlalchemy import create_engine
from nltk.corpus import wordnet
import pandas as pd
import numpy as np
import traceback
import psycopg2
import sys
def load_data(data_file):
try:
df = pd.read_csv(data_file)
except:
print("ERROR: Unable to read data into pandas dataframe")
traceback.print_exc(file=sys.stdout)
sys.exit(0)
return df
def remove_unwanted_rows(df):
def detect_non_english(sentence, m=0):
for words in sentence:
if m == 2:
return True
if not wordnet.synsets(words):
return False
m = m + 1
try:
# remove empty title/descriptions
df['job_description'].replace('', np.nan, inplace=True)
df['job_title'].replace('', np.nan, inplace=True)
df.dropna(subset=['job_description'], inplace=True)
df.dropna(subset=['job_title'], inplace=True)
# remove non english rows
df = df[df.job_title.map(lambda x: detect_non_english(x))]
except:
print("ERROR: Unable to remove unwanted rows from the dataframe")
traceback.print_exc(file=sys.stdout)
sys.exit(0)
return df
def add_new_data(df, file_name):
try:
with open(file_name, 'a') as f:
df.to_csv(f, header=False)
except:
print("ERROR: Unable to save new dataframe to sql table")
traceback.print_exc(file=sys.stdout)
sys.exit(0)
df.check_size
return True if length > 25 else False
def data_collection(data_file):
df = load_data(data_file)
df = remove_unwanted_rows(df)
return df