-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_columns.py
More file actions
42 lines (32 loc) · 1.47 KB
/
Copy pathadd_columns.py
File metadata and controls
42 lines (32 loc) · 1.47 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
import pandas as pd
import json
from tqdm import tqdm
def extract_additional_data(json_string):
try:
data = json.loads(json_string)
person = data.get('person', {})
organization = person.get('organization', {})
employment_history = person.get('employment_history', [])
past_employment_titles = [emp.get('title') for emp in employment_history]
past_employment_descriptions = [emp.get('description') for emp in employment_history]
return {
'summary': person.get('summary'),
'skills': ';'.join(person.get('skills', [])),
'organization_industry': organization.get('industry'),
'past_employment_titles': ';'.join(filter(None, past_employment_titles)),
'past_employment_descriptions': ';'.join(filter(None, past_employment_descriptions)),
}
except (json.JSONDecodeError, AttributeError):
return {
'summary': None,
'skills': None,
'organization_industry': None,
'past_employment_titles': None,
'past_employment_descriptions': None,
}
tqdm.pandas()
df = pd.read_csv('apollo_people_data.csv')
additional_data = df['full_json_response'].progress_apply(extract_additional_data)
new_df = pd.concat([df, pd.json_normalize(additional_data)], axis=1)
new_df.to_csv('apollo_people_data_enriched.csv', index=False)
print("Successfully created apollo_people_data_enriched.csv with additional columns.")