From aaba8fb115f6883e10937d9f57c15bad188f1487 Mon Sep 17 00:00:00 2001 From: yerbol-akhmetov Date: Sat, 20 Apr 2024 15:09:54 +0500 Subject: [PATCH] add OS based encoding --- scripts/build_biomass_transport_costs.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/build_biomass_transport_costs.py b/scripts/build_biomass_transport_costs.py index c20b3882..a54f85be 100644 --- a/scripts/build_biomass_transport_costs.py +++ b/scripts/build_biomass_transport_costs.py @@ -19,13 +19,16 @@ assuming as an approximation energy content of wood pellets import pandas as pd import tabula as tbl +import platform ENERGY_CONTENT = 4.8 # unit MWh/t (wood pellets) +system = platform.system() +encoding = 'cp1252' if system == 'Windows' else None def get_countries(): pandas_options = dict( - skiprows=range(6), header=None, index_col=0, encoding="cp1252" + skiprows=range(6), header=None, index_col=0, encoding=encoding ) return tbl.read_pdf( @@ -33,7 +36,7 @@ def get_countries(): pages="145", multiple_tables=False, pandas_options=pandas_options, - encoding="cp1252", + encoding=encoding, )[0].index @@ -44,7 +47,7 @@ def get_cost_per_tkm(page, countries): sep=" |,", engine="python", index_col=False, - encoding="cp1252", + encoding=encoding, ) sc = tbl.read_pdf( @@ -52,7 +55,7 @@ def get_cost_per_tkm(page, countries): pages=page, multiple_tables=False, pandas_options=pandas_options, - encoding="cp1252", + encoding=encoding, )[0] sc.index = countries sc.columns = sc.columns.str.replace("€", "EUR")