Analyze
This module combines the files together in wide form.
Overview
This module contains the logic for analyzing the data.
It is responsible for combining the data from the different sources and converting into wide format for analysis.
You can actually run this as a script directly from the command line if you cloned the repo.
cleanup_columns(df)
Cleans up the column names IN PLACE.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
pd.DataFrame
|
The data. |
required |
Source code in opendata_pipeline/analyze.py
186 187 188 189 190 191 192 193 194 |
|
combine(base_df, geo_df, drug_df)
Combines the data into a single dataframe.
This function calls make_wide
, merge_wide_drugs_to_records
, and join_geocoded_data
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_df |
pd.DataFrame
|
The base data. |
required |
geo_df |
pd.DataFrame
|
The geocoded data. |
required |
drug_df |
pd.DataFrame
|
The drug data. |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame
|
pd.DataFrame: The combined data. |
Source code in opendata_pipeline/analyze.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
join_geocoded_data(base_df, geo_df)
Joins the geocoded data to the base data.
Merges on index
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_df |
pd.DataFrame
|
The base data. |
required |
geo_df |
pd.DataFrame
|
The geocoded data. |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame
|
pd.DataFrame: The joined data. |
Source code in opendata_pipeline/analyze.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
make_wide(df)
Converts the drug data from long to wide format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
pd.DataFrame
|
The drug data. |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame
|
pd.DataFrame: The drug data in wide format. |
Source code in opendata_pipeline/analyze.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
merge_wide_drugs_to_records(base_df, wide_drug_df)
Merges the wide drug data to the base data (on index).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_df |
pd.DataFrame
|
The base data. |
required |
wide_drug_df |
pd.DataFrame
|
The wide drug data. |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame
|
pd.DataFrame: The joined data. |
Source code in opendata_pipeline/analyze.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
read_drug_data(source)
Reads the drug data from the data directory.
Sets the index to CaseIdentifier
/record_id
, and handles some minor column renaming.
Only returns the data for the given source (i.e. filtered).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
models.DataSource
|
The source to read. |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame
|
pd.DataFrame: The drug data. |
Source code in opendata_pipeline/analyze.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
read_geocoded_data(source)
Reads the geocoded data from the data directory.
Sets the index to CaseIdentifier
, and handles some minor column renaming.
Only returns the data for the given source (i.e. filtered).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
models.DataSource
|
The source to read. |
required |
Returns:
Type | Description |
---|---|
pd.DataFrame
|
pd.DataFrame: The geocoded data. |
Source code in opendata_pipeline/analyze.py
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 |
|
read_records(source)
Reads the records from the data directory, sets index to CaseIdentifier
.
Source code in opendata_pipeline/analyze.py
96 97 98 99 100 101 102 103 104 |
|
run(settings)
Runs the data processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settings |
models.Settings
|
The settings. |
required |
Source code in opendata_pipeline/analyze.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|