Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions statvar_imports/world_bank/commodity_market/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def download_file(url, filename):
raise

def clean_values(df):
return df.applymap(lambda x: pd.NA if isinstance(x, str) and ("..." in x or "…" in x or x.strip() in ["...", "..", "…"]) else x)
return df.map(lambda x: pd.NA if isinstance(x, str) and ("..." in x or "…" in x or x.strip() in ["...", "..", "…"]) else x)

def process_xlsx(file_path):
try:
Expand Down Expand Up @@ -70,7 +70,7 @@ def process_xlsx(file_path):

header_rows = header_rows.ffill(axis=0).infer_objects(copy=False)
header_rows = header_rows.fillna('').astype(str)
header_rows = header_rows.applymap(lambda x: ' '.join(x.split()))
header_rows = header_rows.map(lambda x: ' '.join(x.split()))
combined_header = header_rows.apply(lambda x: ' '.join(dict.fromkeys(x)).strip(), axis=0)
combined_header = combined_header.str.replace(' +', ' ', regex=True)
data_df.columns = combined_header.values
Expand All @@ -92,7 +92,7 @@ def process_xlsx(file_path):

header_rows = header_rows.ffill(axis=0).infer_objects(copy=False)
header_rows = header_rows.fillna('').astype(str)
header_rows = header_rows.applymap(lambda x: ' '.join(x.split()))
header_rows = header_rows.map(lambda x: ' '.join(x.split()))
combined_header = header_rows.apply(lambda x: ' '.join(dict.fromkeys(x)).strip(), axis=0)
combined_header = combined_header.str.replace(' +', ' ', regex=True)
data_df.columns = combined_header.values
Expand All @@ -114,7 +114,8 @@ def process_xlsx(file_path):
logging.info(f"Skipping unrecognized sheet: {sheet_name}")

except Exception as e:
logging.error(f"Failed to process {file_path}: {e}")
logging.exception(f"Failed to process {file_path}")
raise

def main():
logging.set_verbosity(logging.DEBUG)
Expand Down
Loading