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.
add_death_date_breakdowns(df, source)
Adds death date breakdowns to the data IN PLACE.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The records dataframe. |
required |
source
|
DataSource
|
The source config |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The records dataframe with death date breakdowns added. |
Source code in src/opendata_pipeline/analyze.py
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 136 |
|
cleanup_columns(df)
Cleans up the column names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The data. |
required |
Source code in src/opendata_pipeline/analyze.py
222 223 224 225 226 227 228 229 230 |
|
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
|
DataFrame
|
The base data. |
required |
geo_df
|
DataFrame
|
The geocoded data. |
required |
drug_df
|
DataFrame
|
The drug data. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The combined data. |
Source code in src/opendata_pipeline/analyze.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
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
|
DataFrame
|
The base data. |
required |
geo_df
|
DataFrame
|
The geocoded data. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The joined data. |
Source code in src/opendata_pipeline/analyze.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
make_wide(df)
Converts the drug data from long to wide format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The drug data. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The drug data in wide format. |
Source code in src/opendata_pipeline/analyze.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
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
|
DataFrame
|
The base data. |
required |
wide_drug_df
|
DataFrame
|
The wide drug data. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The joined data. |
Source code in src/opendata_pipeline/analyze.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
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
|
DataSource
|
The source to read. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The drug data. |
Source code in src/opendata_pipeline/analyze.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
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
|
DataSource
|
The source to read. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The geocoded data. |
Source code in src/opendata_pipeline/analyze.py
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 |
|
read_records(source)
Reads the records from the data directory, sets index to CaseIdentifier
.
Source code in src/opendata_pipeline/analyze.py
98 99 100 101 102 103 104 105 106 |
|
run(settings)
Runs the data processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settings
|
Settings
|
The settings. |
required |
Source code in src/opendata_pipeline/analyze.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|