I converted a JSON variable to multiple paired variables. As a result, I have a dataset like
home_city_1 home_number_1 home_city_2 home_number_2 home_city_3 home_number_3 home_city_4 home_number_4
Coeur D Alene, ID 13.0 Hayden, ID 8.0 Renton, WA 2.0 NaN NaN
Spokane, WA 3.0 Amber, WA 2.0 NaN NaN NaN NaN
Sioux Falls, SD 9.0 Stone Mountain, GA 2.0 Watertown, SD 2.0 Dell Rapids, SD 2.0
Ludowici, GA 11.0 NaN NaN NaN NaN NaN NaN
This data set has 600 columns (300 * 2).
I want to convert the values with those conditions:
- Change ' ' or ',' in the home_city_# column values to '_' (under bar). For example, 'Sioux Falls, SD' to 'Sioux_Falls__SD'
- Convert missing values to 'm' (missing in home_city_#) or -1 (missing in home_number_#)
I have tried
customer_home_city_json_2 = customer_home_city_json_1.replace(',', '_')
customer_home_city_json_2 = customer_home_city_json_2 .apply(lambda x: x.replace('null', "-1"))