Skip to content

Commit

Permalink
Minor renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGherardelli committed Jun 24, 2024
1 parent 329e588 commit 61dabf2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions data_bridges_knots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"""

from .client import DataBridgesShapes
from .labels import get_column_labels, get_value_labels, map_value_labels
from .helpers import get_column_labels, get_value_labels, map_value_labels

__all__ = ['DataBridgesShapes', 'labels']
__all__ = ['DataBridgesShapes', 'helpers']
5 changes: 4 additions & 1 deletion data_bridges_knots/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ def get_household_survey(self, survey_id, access_type, page_size=600):

df = pd.DataFrame(responses)

df.apply(lambda x: pd.to_numeric(x, errors='coerce', downcast='integer').fillna(9999).astype(np.int64 if x.dtype == 'int64' else x.dtype))
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

Expand Down
14 changes: 10 additions & 4 deletions data_bridges_knots/labels.py → data_bridges_knots/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def get_value_labels(df):
name = row["name"]
choice = row["choices"]
if name in categories_dict:
categories_dict[name].update({int(choice["name"]): choice["label"]})
categories_dict[name].update({(choice["name"]): choice["label"]})
else:
categories_dict[name] = {int(choice["name"]): choice["label"]}
categories_dict[name] = {(choice["name"]): choice["label"]}
return categories_dict

def get_column_labels(df):
Expand Down Expand Up @@ -42,9 +42,9 @@ def map_value_labels(survey_data, questionnaire):
name = row["name"]
choice = row["choices"]
if name in categories_dict:
categories_dict[name].update({int(choice["name"]): choice["label"]})
categories_dict[name].update({(choice["name"]): choice["label"]})
else:
categories_dict[name] = {int(choice["name"]): choice["label"]}
categories_dict[name] = {(choice["name"]): choice["label"]}

# Map the categories to survey_data
survey_data_value_labels = survey_data.copy()
Expand All @@ -55,3 +55,9 @@ 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))
return df


0 comments on commit 61dabf2

Please sign in to comment.