-
Notifications
You must be signed in to change notification settings - Fork 0
/
Merging.py
36 lines (22 loc) · 1.06 KB
/
Merging.py
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
'''
This program merge the senctencing data and prosecutor data together and produce
a csv file of merged data and a txt file for unique values in each column
'''
import pandas as pd
Prosecutor_Data = pd.read_csv('Data/Prosecutor Data-01-25-2023_name_rem.csv')
Sentencing_Data = pd.read_csv('Data/Sentencing Information-01-25-2023_name_rem.csv')
Victim_Data = pd.read_csv('Data/Victim Data-01-25-2023_name_rem.csv')
Sentencing_Data['Matching_ID'] = Sentencing_Data.CaseNbr + Sentencing_Data.PartyID.astype(str)
Prosecutor_Data['Matching_ID'] = Prosecutor_Data.CaseNumber + Prosecutor_Data.UniquePersonID.astype(str)
Merged = Sentencing_Data.merge(Prosecutor_Data, on='Matching_ID', how='left')
Merged.to_csv("test.csv")
col_values = []
for col in Merged:
col_values.append(Merged[col].unique())
col_names = []
for col in Merged.columns:
col_names.append(col)
uniqe_value = {col_names[i]: col_values[i] for i in range(len(col_names))}
with open("unqie_value.txt", 'w') as f:
for key, value in uniqe_value.items():
f.write('%s:%s\n' % (key, value))