Skip to content

Commit

Permalink
Fix collection_month_name bug to account for NaN values
Browse files Browse the repository at this point in the history
  • Loading branch information
Natalie-Winans committed Jan 6, 2025
1 parent 9f705be commit f8e3114
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,14 @@ def retrieve_metadata_records(self, unique_field: str) -> pd.DataFrame:
df["collection_month"] = df["collection_date"].str.split("-").str[1]
df["collection_day"] = df["collection_date"].str.split("-").str[2]

df["collection_month_name"] = df["collection_month"].apply(
lambda x: calendar.month_name[int(x)]
)
# Safely map collection_month to month_name (account for NaN values)
def get_month_name(month):
try:
return calendar.month_name[int(month)]
except (ValueError, TypeError):
return "" # return empty string for invalid cases

df["collection_month_name"] = df["collection_month"].apply(get_month_name)

return df

Expand Down

0 comments on commit f8e3114

Please sign in to comment.