<jupyter_start><jupyter_text>Read in json line file<jupyter_code>board_data = []
with open('company-officers-v2.json') as f:
    for line in f:
        board_data.append(json.loads(line))
board_data[1]<jupyter_output><empty_output><jupyter_text>Read out board member informationand write into json file<jupyter_code>for i in range(len(board_data)):
    company = board_data[i]['company_number']
    list_of_people = board_data[i]['data']['items']
    
    for n in range(len(list_of_people)):    
            new_person = {}
            new_person['company_number'] = company

            if 'name' in list_of_people[n]:
                new_person['name'] = list_of_people[n]['name']
            else:
                new_person['name'] = None

            if 'appointed_on' in list_of_people[n]:
                new_person['appointed_on'] = list_of_people[n]['appointed_on']
            else:
                new_person['appointed_on'] = None    

            if 'date_of_birth' in list_of_people[n] and 'year' in list_of_people[n]['date_of_birth']:                
                new_person['year_of_birth'] = list_of_people[n]['date_of_birth']['year']
            else:
                new_person['year_of_birth'] = None                

            if 'nationality' in list_of_people[n]:            
                new_person['nationality'] = list_of_people[n]['nationality']
            else:
                new_person['nationality'] = None                

            if 'occupation' in list_of_people[n]:            
                new_person['occupation'] = list_of_people[n]['occupation']
            else:
                new_person['occupation'] = None                

            if 'officer_role' in list_of_people[n]:            
                new_person['officer_role'] = list_of_people[n]['officer_role']
            else:
                new_person['officer_role'] = None                
            
            if 'resigned_on' in list_of_people[n]:                        
                new_person['resigned_on'] = list_of_people[n]['resigned_on']
            else:
                new_person['resigned_on'] = None                
            
            with open('board_members.json', 'a') as f:
                f.write(json.dumps(new_person))
                f.write('\n')

# Read the json file back in
board_members = pd.read_json('board_members.json', lines=True)
board_members.head()
board_members.year_of_birth.unique()
# Some name processing
names = board_members['name'].str.split(',', expand=True)
names.head()
surname = names.iloc[:,0]
title = names.iloc[:,2]
second_title = names.iloc[:,3]

first_names = names.iloc[:,1].str.split(' ', expand=True)
first_names.head()
first_name = first_names.iloc[:,1]
middle_name_1 = first_names.iloc[:,2]
middle_name_2 = first_names.iloc[:,3]
middle_name_3 = first_names.iloc[:,4]
board_members['surname'] = surname
board_members['first_name'] = first_name
board_members['middle_name_1'] = middle_name_1
board_members['middle_name_2'] = middle_name_2
board_members['middle_name_3'] = middle_name_3
board_members['title'] = title
board_members['second_title'] = second_title
board_members.head()
board_members.to_csv('Board_members.csv', sep=',')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12415488629379226, 'fraction_numerical': 0.005838967424708051, 'mean_word_length': 2.522727272727273, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '29329', 'license': 'MIT', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1010, 'n_words': 164, 'path': 'companies-house-api/Board-members_data-processing.ipynb', 'repo_name': 'suganya-s/mentors-repo', 'size': '3254'}