Skip to content

Commit

Permalink
Change mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGherardelli committed Jun 24, 2024
1 parent 61dabf2 commit 79ba1f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 0 additions & 4 deletions data_bridges_knots/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ def get_household_survey(self, survey_id, access_type, page_size=600):

df = pd.DataFrame(responses)

df = df.apply(lambda x: pd.to_numeric(x, errors='ignore', downcast='integer').fillna(9999).astype(int if x.dtype == 'int' or x.dtype == 'float' else x.dtype))

# df = df.apply(lambda x: pd.to_numeric(x, errors='ignore', downcast='integer').fillna(9999).astype(int if x.dtype == 'float' else x.dtype))

df = df.replace({9999: None})
return df

def get_prices(self, country_iso3, survey_date, page_size=1000):
Expand Down
9 changes: 6 additions & 3 deletions data_bridges_knots/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def get_column_labels(df):

# Map values if int
def map_value_labels(survey_data, questionnaire):

survey_data = survey_data.convert_dtypes()
choiceList = pd.json_normalize(questionnaire['choiceList'])
choiceList = choiceList.rename(columns={"name": "choice_name"})
choiceList = choiceList.join(questionnaire["name"]).dropna()
Expand All @@ -55,9 +57,10 @@ def map_value_labels(survey_data, questionnaire):

return survey_data_value_labels

def as_numeric(df, cols = []):
for col in cols:
df[col].apply(lambda x: x.astype(int))
def as_numeric(df, col_list):
for col in col_list:
df[col] = pd.to_numeric(df[col], errors='ignore').fillna(9999).astype('int64')

return df


0 comments on commit 79ba1f3

Please sign in to comment.