diff --git a/investpy/bonds.py b/investpy/bonds.py index cbec73f6..3bde60ad 100644 --- a/investpy/bonds.py +++ b/investpy/bonds.py @@ -243,12 +243,12 @@ def get_bond_recent_data(bond, as_json=False, order='ascending', interval='Daily bond = unidecode(bond.strip().lower()) - if bond not in list(bonds['name'].str.lower()): + if bond not in list(bonds['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0068: bond " + bond + " not found, check if it is correct.") - id_ = bonds.loc[(bonds['name'].str.lower() == bond).idxmax(), 'id'] - name = bonds.loc[(bonds['name'].str.lower() == bond).idxmax(), 'name'] - full_name = bonds.loc[(bonds['name'].str.lower() == bond).idxmax(), 'full_name'] + id_ = bonds.loc[(bonds['name'].apply(unidecode).str.lower() == bond).idxmax(), 'id'] + name = bonds.loc[(bonds['name'].apply(unidecode).str.lower() == bond).idxmax(), 'name'] + full_name = bonds.loc[(bonds['name'].apply(unidecode).str.lower() == bond).idxmax(), 'full_name'] header = full_name + " Bond Yield Historical Data" @@ -475,12 +475,12 @@ def get_bond_historical_data(bond, from_date, to_date, as_json=False, order='asc bond = unidecode(bond.strip().lower()) - if bond not in list(bonds['name'].str.lower()): + if bond not in list(bonds['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0068: bond " + bond + " not found, check if it is correct.") - id_ = bonds.loc[(bonds['name'].str.lower() == bond).idxmax(), 'id'] - name = bonds.loc[(bonds['name'].str.lower() == bond).idxmax(), 'name'] - full_name = bonds.loc[(bonds['name'].str.lower() == bond).idxmax(), 'full_name'] + id_ = bonds.loc[(bonds['name'].apply(unidecode).str.lower() == bond).idxmax(), 'id'] + name = bonds.loc[(bonds['name'].apply(unidecode).str.lower() == bond).idxmax(), 'name'] + full_name = bonds.loc[(bonds['name'].apply(unidecode).str.lower() == bond).idxmax(), 'full_name'] final = list() @@ -643,11 +643,11 @@ def get_bond_information(bond, as_json=False): bond = unidecode(bond.strip().lower()) - if bond not in list(bonds['name'].str.lower()): + if bond not in list(bonds['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0068: bond " + bond + " not found, check if it is correct.") - name = bonds.loc[(bonds['name'].str.lower() == bond).idxmax(), 'name'] - tag = bonds.loc[(bonds['name'].str.lower() == bond).idxmax(), 'tag'] + name = bonds.loc[(bonds['name'].apply(unidecode).str.lower() == bond).idxmax(), 'name'] + tag = bonds.loc[(bonds['name'].apply(unidecode).str.lower() == bond).idxmax(), 'tag'] url = "https://www.investing.com/rates-bonds/" + tag diff --git a/investpy/certificates.py b/investpy/certificates.py index 4b0d0c71..965ca757 100644 --- a/investpy/certificates.py +++ b/investpy/certificates.py @@ -264,12 +264,12 @@ def get_certificate_recent_data(certificate, country, as_json=False, order='asce certificate = unidecode(certificate.strip().lower()) - if certificate not in list(certificates['name'].str.lower()): + if certificate not in list(certificates['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0101: certificate " + certificate + " not found, check if it is correct.") - symbol = certificates.loc[(certificates['name'].str.lower() == certificate).idxmax(), 'symbol'] - id_ = certificates.loc[(certificates['name'].str.lower() == certificate).idxmax(), 'id'] - name = certificates.loc[(certificates['name'].str.lower() == certificate).idxmax(), 'name'] + symbol = certificates.loc[(certificates['name'].apply(unidecode).str.lower() == certificate).idxmax(), 'symbol'] + id_ = certificates.loc[(certificates['name'].apply(unidecode).str.lower() == certificate).idxmax(), 'id'] + name = certificates.loc[(certificates['name'].apply(unidecode).str.lower() == certificate).idxmax(), 'name'] header = symbol + ' Historical Data' @@ -510,12 +510,12 @@ def get_certificate_historical_data(certificate, country, from_date, to_date, as certificate = unidecode(certificate.strip().lower()) - if certificate not in list(certificates['name'].str.lower()): + if certificate not in list(certificates['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0101: certificate " + certificate + " not found, check if it is correct.") - symbol = certificates.loc[(certificates['name'].str.lower() == certificate).idxmax(), 'symbol'] - id_ = certificates.loc[(certificates['name'].str.lower() == certificate).idxmax(), 'id'] - name = certificates.loc[(certificates['name'].str.lower() == certificate).idxmax(), 'name'] + symbol = certificates.loc[(certificates['name'].apply(unidecode).str.lower() == certificate).idxmax(), 'symbol'] + id_ = certificates.loc[(certificates['name'].apply(unidecode).str.lower() == certificate).idxmax(), 'id'] + name = certificates.loc[(certificates['name'].apply(unidecode).str.lower() == certificate).idxmax(), 'name'] header = symbol + ' Historical Data' @@ -690,11 +690,11 @@ def get_certificate_information(certificate, country, as_json=False): certificate = unidecode(certificate.strip().lower()) - if certificate not in list(certificates['name'].str.lower()): + if certificate not in list(certificates['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0101: certificate " + certificate + " not found, check if it is correct.") - tag = certificates.loc[(certificates['name'].str.lower() == certificate).idxmax(), 'tag'] - name = certificates.loc[(certificates['name'].str.lower() == certificate).idxmax(), 'name'] + tag = certificates.loc[(certificates['name'].apply(unidecode).str.lower() == certificate).idxmax(), 'tag'] + name = certificates.loc[(certificates['name'].apply(unidecode).str.lower() == certificate).idxmax(), 'name'] url = "https://www.investing.com/certificates/" + tag diff --git a/investpy/commodities.py b/investpy/commodities.py index 7828dacf..bb4af468 100644 --- a/investpy/commodities.py +++ b/investpy/commodities.py @@ -255,11 +255,11 @@ def get_commodity_recent_data(commodity, country=None, as_json=False, order='asc commodity = unidecode(commodity.strip().lower()) - if commodity not in list(commodities['name'].str.lower()): + if commodity not in list(commodities['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0079: commodity " + commodity + " not found, check if it is correct.") if country is None: - found_commodities = commodities[commodities['name'].str.lower() == commodity] + found_commodities = commodities[commodities['name'].apply(unidecode).str.lower() == commodity] if len(found_commodities) > 1: msg = "Note that the displayed commodity data can differ depending on the country. " \ @@ -276,11 +276,11 @@ def get_commodity_recent_data(commodity, country=None, as_json=False, order='asc commodities = commodities[commodities['country'] == country] - full_name = commodities.loc[(commodities['name'].str.lower() == commodity).idxmax(), 'full_name'] - id_ = commodities.loc[(commodities['name'].str.lower() == commodity).idxmax(), 'id'] - name = commodities.loc[(commodities['name'].str.lower() == commodity).idxmax(), 'name'] + full_name = commodities.loc[(commodities['name'].apply(unidecode).str.lower() == commodity).idxmax(), 'full_name'] + id_ = commodities.loc[(commodities['name'].apply(unidecode).str.lower() == commodity).idxmax(), 'id'] + name = commodities.loc[(commodities['name'].apply(unidecode).str.lower() == commodity).idxmax(), 'name'] - currency = commodities.loc[(commodities['name'].str.lower() == commodity).idxmax(), 'currency'] + currency = commodities.loc[(commodities['name'].apply(unidecode).str.lower() == commodity).idxmax(), 'currency'] header = full_name + ' Historical Data' @@ -516,11 +516,11 @@ def get_commodity_historical_data(commodity, from_date, to_date, country=None, a commodity = unidecode(commodity.strip().lower()) - if commodity not in list(commodities['name'].str.lower()): + if commodity not in list(commodities['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0079: commodity " + commodity + " not found, check if it is correct.") if country is None: - found_commodities = commodities[commodities['name'].str.lower() == commodity] + found_commodities = commodities[commodities['name'].apply(unidecode).str.lower() == commodity] if len(found_commodities) > 1: msg = "Note that the displayed commodity data can differ depending on the country. " \ @@ -537,11 +537,11 @@ def get_commodity_historical_data(commodity, from_date, to_date, country=None, a commodities = commodities[commodities['country'] == country] - full_name = commodities.loc[(commodities['name'].str.lower() == commodity).idxmax(), 'full_name'] - id_ = commodities.loc[(commodities['name'].str.lower() == commodity).idxmax(), 'id'] - name = commodities.loc[(commodities['name'].str.lower() == commodity).idxmax(), 'name'] + full_name = commodities.loc[(commodities['name'].apply(unidecode).str.lower() == commodity).idxmax(), 'full_name'] + id_ = commodities.loc[(commodities['name'].apply(unidecode).str.lower() == commodity).idxmax(), 'id'] + name = commodities.loc[(commodities['name'].apply(unidecode).str.lower() == commodity).idxmax(), 'name'] - currency = commodities.loc[(commodities['name'].str.lower() == commodity).idxmax(), 'currency'] + currency = commodities.loc[(commodities['name'].apply(unidecode).str.lower() == commodity).idxmax(), 'currency'] header = full_name + ' Historical Data' @@ -720,11 +720,11 @@ def get_commodity_information(commodity, country=None, as_json=False): commodity = unidecode(commodity.strip().lower()) - if commodity not in list(commodities['name'].str.lower()): + if commodity not in list(commodities['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0079: commodity " + commodity + " not found, check if it is correct.") if country is None: - found_commodities = commodities[commodities['name'].str.lower() == commodity] + found_commodities = commodities[commodities['name'].apply(unidecode).str.lower() == commodity] if len(found_commodities) > 1: msg = "Note that the displayed commodity information can differ depending on the country. " \ @@ -741,8 +741,8 @@ def get_commodity_information(commodity, country=None, as_json=False): commodities = commodities[commodities['country'] == country] - name = commodities.loc[(commodities['name'].str.lower() == commodity).idxmax(), 'name'] - tag = commodities.loc[(commodities['name'].str.lower() == commodity).idxmax(), 'tag'] + name = commodities.loc[(commodities['name'].apply(unidecode).str.lower() == commodity).idxmax(), 'name'] + tag = commodities.loc[(commodities['name'].apply(unidecode).str.lower() == commodity).idxmax(), 'tag'] url = "https://www.investing.com/commodities/" + tag diff --git a/investpy/crypto.py b/investpy/crypto.py index 626c11cb..b2d13396 100644 --- a/investpy/crypto.py +++ b/investpy/crypto.py @@ -216,16 +216,16 @@ def get_crypto_recent_data(crypto, as_json=False, order='ascending', interval='D crypto = unidecode(crypto.strip().lower()) - if crypto not in list(cryptos['name'].str.lower()): + if crypto not in list(cryptos['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0085: crypto currency: " + crypto + ", not found, check if it is correct.") - status = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'status'] + status = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'status'] if status == 'unavailable': raise ValueError("ERR#0086: the selected crypto currency is not available for retrieval in Investing.com.") - crypto_name = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'name'] - crypto_id = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'id'] - crypto_currency = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'currency'] + crypto_name = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'name'] + crypto_id = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'id'] + crypto_currency = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'currency'] header = crypto_name + ' Historical Data' @@ -455,16 +455,16 @@ def get_crypto_historical_data(crypto, from_date, to_date, as_json=False, order= crypto = unidecode(crypto.strip().lower()) - if crypto not in list(cryptos['name'].str.lower()): + if crypto not in list(cryptos['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0085: crypto currency: " + crypto + ", not found, check if it is correct.") - status = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'status'] + status = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'status'] if status == 'unavailable': raise ValueError("ERR#0086: the selected crypto currency is not available for retrieval in Investing.com.") - crypto_name = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'name'] - crypto_id = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'id'] - crypto_currency = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'currency'] + crypto_name = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'name'] + crypto_id = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'id'] + crypto_currency = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'currency'] header = crypto_name + ' Historical Data' @@ -628,16 +628,16 @@ def get_crypto_information(crypto, as_json=False): crypto = unidecode(crypto.strip().lower()) - if crypto not in list(cryptos['name'].str.lower()): + if crypto not in list(cryptos['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0085: crypto currency: " + crypto + ", not found, check if it is correct.") - status = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'status'] + status = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'status'] if status == 'unavailable': raise ValueError("ERR#0086: the selected crypto currency is not available for retrieval in Investing.com.") - name = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'name'] - currency = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'currency'] - tag = cryptos.loc[(cryptos['name'].str.lower() == crypto).idxmax(), 'tag'] + name = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'name'] + currency = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'currency'] + tag = cryptos.loc[(cryptos['name'].apply(unidecode).str.lower() == crypto).idxmax(), 'tag'] url = "https://www.investing.com/crypto/" + tag diff --git a/investpy/currency_crosses.py b/investpy/currency_crosses.py index 0ff80531..76e8fb58 100644 --- a/investpy/currency_crosses.py +++ b/investpy/currency_crosses.py @@ -278,12 +278,12 @@ def get_currency_cross_recent_data(currency_cross, as_json=False, order='ascendi currency_cross = unidecode(currency_cross.strip().lower()) - if currency_cross not in list(currency_crosses['name'].str.lower()): + if currency_cross not in list(currency_crosses['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0054: the introduced currency_cross " + str(currency_cross) + " does not exist.") - id_ = currency_crosses.loc[(currency_crosses['name'].str.lower() == currency_cross).idxmax(), 'id'] - name = currency_crosses.loc[(currency_crosses['name'].str.lower() == currency_cross).idxmax(), 'name'] - currency = currency_crosses.loc[(currency_crosses['name'].str.lower() == currency_cross).idxmax(), 'second'] + id_ = currency_crosses.loc[(currency_crosses['name'].apply(unidecode).str.lower() == currency_cross).idxmax(), 'id'] + name = currency_crosses.loc[(currency_crosses['name'].apply(unidecode).str.lower() == currency_cross).idxmax(), 'name'] + currency = currency_crosses.loc[(currency_crosses['name'].apply(unidecode).str.lower() == currency_cross).idxmax(), 'second'] header = name + ' Historical Data' @@ -508,12 +508,12 @@ def get_currency_cross_historical_data(currency_cross, from_date, to_date, as_js currency_cross = unidecode(currency_cross.strip().lower()) - if currency_cross not in list(currency_crosses['name'].str.lower()): + if currency_cross not in list(currency_crosses['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0054: the introduced currency_cross " + str(currency_cross) + " does not exist.") - id_ = currency_crosses.loc[(currency_crosses['name'].str.lower() == currency_cross).idxmax(), 'id'] - name = currency_crosses.loc[(currency_crosses['name'].str.lower() == currency_cross).idxmax(), 'name'] - currency = currency_crosses.loc[(currency_crosses['name'].str.lower() == currency_cross).idxmax(), 'second'] + id_ = currency_crosses.loc[(currency_crosses['name'].apply(unidecode).str.lower() == currency_cross).idxmax(), 'id'] + name = currency_crosses.loc[(currency_crosses['name'].apply(unidecode).str.lower() == currency_cross).idxmax(), 'name'] + currency = currency_crosses.loc[(currency_crosses['name'].apply(unidecode).str.lower() == currency_cross).idxmax(), 'second'] final = list() @@ -675,11 +675,11 @@ def get_currency_cross_information(currency_cross, as_json=False): currency_cross = unidecode(currency_cross.strip().lower()) - if currency_cross not in list(currency_crosses['name'].str.lower()): + if currency_cross not in list(currency_crosses['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0054: the introduced currency_cross " + str(currency_cross) + " does not exist.") - name = currency_crosses.loc[(currency_crosses['name'].str.lower() == currency_cross).idxmax(), 'name'] - tag = currency_crosses.loc[(currency_crosses['name'].str.lower() == currency_cross).idxmax(), 'tag'] + name = currency_crosses.loc[(currency_crosses['name'].apply(unidecode).str.lower() == currency_cross).idxmax(), 'name'] + tag = currency_crosses.loc[(currency_crosses['name'].apply(unidecode).str.lower() == currency_cross).idxmax(), 'tag'] url = "https://www.investing.com/currencies/" + tag diff --git a/investpy/etfs.py b/investpy/etfs.py index 4bc49ea4..9d0ba6f1 100644 --- a/investpy/etfs.py +++ b/investpy/etfs.py @@ -273,14 +273,14 @@ def get_etf_recent_data(etf, country, stock_exchange=None, as_json=False, order= etf = unidecode(etf.strip().lower()) - def_exchange = etfs.loc[((etfs['name'].str.lower() == etf) & (etfs['def_stock_exchange'] == True)).idxmax()] + def_exchange = etfs.loc[((etfs['name'].apply(unidecode).str.lower() == etf) & (etfs['def_stock_exchange'] == True)).idxmax()] etfs = etfs[etfs['country'].str.lower() == country] - if etf not in list(etfs['name'].str.lower()): + if etf not in list(etfs['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0019: etf " + etf + " not found, check if it is correct.") - etfs = etfs[etfs['name'].str.lower() == etf] + etfs = etfs[etfs['name'].apply(unidecode).str.lower() == etf] if def_exchange['country'] != country: warnings.warn( @@ -296,7 +296,7 @@ def get_etf_recent_data(etf, country, stock_exchange=None, as_json=False, order= etf_exchange = etfs.loc[(etfs['stock_exchange'].str.lower() == stock_exchange.lower()).idxmax(), 'stock_exchange'] else: - found_etfs = etfs[etfs['name'].str.lower() == etf] + found_etfs = etfs[etfs['name'].apply(unidecode).str.lower() == etf] if len(found_etfs) > 1: warnings.warn( @@ -307,7 +307,7 @@ def get_etf_recent_data(etf, country, stock_exchange=None, as_json=False, order= del found_etfs - etf_exchange = etfs.loc[(etfs['name'].str.lower() == etf).idxmax(), 'stock_exchange'] + etf_exchange = etfs.loc[(etfs['name'].apply(unidecode).str.lower() == etf).idxmax(), 'stock_exchange'] else: if stock_exchange: if stock_exchange.lower() not in etfs['stock_exchange'].str.lower(): @@ -325,11 +325,11 @@ def get_etf_recent_data(etf, country, stock_exchange=None, as_json=False, order= else: etf_exchange = def_exchange['stock_exchange'] - symbol = etfs.loc[((etfs['name'].str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'symbol'] - id_ = etfs.loc[((etfs['name'].str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'id'] - name = etfs.loc[((etfs['name'].str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'name'] + symbol = etfs.loc[((etfs['name'].apply(unidecode).str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'symbol'] + id_ = etfs.loc[((etfs['name'].apply(unidecode).str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'id'] + name = etfs.loc[((etfs['name'].apply(unidecode).str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'name'] - etf_currency = etfs.loc[((etfs['name'].str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'currency'] + etf_currency = etfs.loc[((etfs['name'].apply(unidecode).str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'currency'] header = symbol + ' Historical Data' @@ -574,14 +574,14 @@ def get_etf_historical_data(etf, country, from_date, to_date, stock_exchange=Non etf = unidecode(etf.strip().lower()) - def_exchange = etfs.loc[((etfs['name'].str.lower() == etf) & (etfs['def_stock_exchange'] == True)).idxmax()] + def_exchange = etfs.loc[((etfs['name'].apply(unidecode).str.lower() == etf) & (etfs['def_stock_exchange'] == True)).idxmax()] etfs = etfs[etfs['country'].str.lower() == country] - if etf not in list(etfs['name'].str.lower()): + if etf not in list(etfs['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0019: etf " + etf + " not found, check if it is correct.") - etfs = etfs[etfs['name'].str.lower() == etf] + etfs = etfs[etfs['name'].apply(unidecode).str.lower() == etf] if def_exchange['country'] != country: warnings.warn( @@ -597,7 +597,7 @@ def get_etf_historical_data(etf, country, from_date, to_date, stock_exchange=Non etf_exchange = etfs.loc[(etfs['stock_exchange'].str.lower() == stock_exchange.lower()).idxmax(), 'stock_exchange'] else: - found_etfs = etfs[etfs['name'].str.lower() == etf] + found_etfs = etfs[etfs['name'].apply(unidecode).str.lower() == etf] if len(found_etfs) > 1: warnings.warn( @@ -608,7 +608,7 @@ def get_etf_historical_data(etf, country, from_date, to_date, stock_exchange=Non del found_etfs - etf_exchange = etfs.loc[(etfs['name'].str.lower() == etf).idxmax(), 'stock_exchange'] + etf_exchange = etfs.loc[(etfs['name'].apply(unidecode).str.lower() == etf).idxmax(), 'stock_exchange'] else: if stock_exchange: if stock_exchange.lower() not in etfs['stock_exchange'].str.lower(): @@ -626,11 +626,11 @@ def get_etf_historical_data(etf, country, from_date, to_date, stock_exchange=Non else: etf_exchange = def_exchange['stock_exchange'] - symbol = etfs.loc[((etfs['name'].str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'symbol'] - id_ = etfs.loc[((etfs['name'].str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'id'] - name = etfs.loc[((etfs['name'].str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'name'] + symbol = etfs.loc[((etfs['name'].apply(unidecode).str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'symbol'] + id_ = etfs.loc[((etfs['name'].apply(unidecode).str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'id'] + name = etfs.loc[((etfs['name'].apply(unidecode).str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'name'] - etf_currency = etfs.loc[((etfs['name'].str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'currency'] + etf_currency = etfs.loc[((etfs['name'].apply(unidecode).str.lower() == etf) & (etfs['stock_exchange'].str.lower() == etf_exchange.lower())).idxmax(), 'currency'] final = list() @@ -815,11 +815,11 @@ def get_etf_information(etf, country, as_json=False): etf = unidecode(etf.strip().lower()) - if etf not in list(etfs['name'].str.lower()): + if etf not in list(etfs['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0019: etf " + etf + " not found, check if it is correct.") - name = etfs.loc[(etfs['name'].str.lower() == etf).idxmax(), 'name'] - tag = etfs.loc[(etfs['name'].str.lower() == etf).idxmax(), 'tag'] + name = etfs.loc[(etfs['name'].apply(unidecode).str.lower() == etf).idxmax(), 'name'] + tag = etfs.loc[(etfs['name'].apply(unidecode).str.lower() == etf).idxmax(), 'tag'] url = "https://www.investing.com/etfs/" + tag diff --git a/investpy/funds.py b/investpy/funds.py index b1f8ce91..01a3c8cf 100644 --- a/investpy/funds.py +++ b/investpy/funds.py @@ -257,13 +257,13 @@ def get_fund_recent_data(fund, country, as_json=False, order='ascending', interv fund = unidecode(fund.strip().lower()) - if fund not in list(funds['name'].str.lower()): + if fund not in list(funds['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0019: fund " + fund + " not found, check if it is correct.") - symbol = funds.loc[(funds['name'].str.lower() == fund).idxmax(), 'symbol'] - id_ = funds.loc[(funds['name'].str.lower() == fund).idxmax(), 'id'] - name = funds.loc[(funds['name'].str.lower() == fund).idxmax(), 'name'] - fund_currency = funds.loc[(funds['name'].str.lower() == fund).idxmax(), 'currency'] + symbol = funds.loc[(funds['name'].apply(unidecode).str.lower() == fund).idxmax(), 'symbol'] + id_ = funds.loc[(funds['name'].apply(unidecode).str.lower() == fund).idxmax(), 'id'] + name = funds.loc[(funds['name'].apply(unidecode).str.lower() == fund).idxmax(), 'name'] + fund_currency = funds.loc[(funds['name'].apply(unidecode).str.lower() == fund).idxmax(), 'currency'] header = symbol + ' Historical Data' @@ -502,13 +502,13 @@ def get_fund_historical_data(fund, country, from_date, to_date, as_json=False, o fund = unidecode(fund.strip().lower()) - if fund not in list(funds['name'].str.lower()): + if fund not in list(funds['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0019: fund " + fund + " not found, check if it is correct.") - symbol = funds.loc[(funds['name'].str.lower() == fund).idxmax(), 'symbol'] - id_ = funds.loc[(funds['name'].str.lower() == fund).idxmax(), 'id'] - name = funds.loc[(funds['name'].str.lower() == fund).idxmax(), 'name'] - fund_currency = funds.loc[(funds['name'].str.lower() == fund).idxmax(), 'currency'] + symbol = funds.loc[(funds['name'].apply(unidecode).str.lower() == fund).idxmax(), 'symbol'] + id_ = funds.loc[(funds['name'].apply(unidecode).str.lower() == fund).idxmax(), 'id'] + name = funds.loc[(funds['name'].apply(unidecode).str.lower() == fund).idxmax(), 'name'] + fund_currency = funds.loc[(funds['name'].apply(unidecode).str.lower() == fund).idxmax(), 'currency'] final = list() @@ -683,10 +683,10 @@ def get_fund_information(fund, country, as_json=False): fund = unidecode(fund.strip().lower()) - if fund not in list(funds['name'].str.lower()): + if fund not in list(funds['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0019: fund " + fund + " not found, check if it is correct.") - tag = funds.loc[(funds['name'].str.lower() == fund).idxmax(), 'tag'] + tag = funds.loc[(funds['name'].apply(unidecode).str.lower() == fund).idxmax(), 'tag'] url = "https://www.investing.com/funds/" + tag diff --git a/investpy/indices.py b/investpy/indices.py index 342ca2f9..eb074bd0 100644 --- a/investpy/indices.py +++ b/investpy/indices.py @@ -258,14 +258,14 @@ def get_index_recent_data(index, country, as_json=False, order='ascending', inte index = unidecode(index.strip().lower()) - if index not in list(indices['name'].str.lower()): + if index not in list(indices['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0045: index " + index + " not found, check if it is correct.") - full_name = indices.loc[(indices['name'].str.lower() == index).idxmax(), 'full_name'] - id_ = indices.loc[(indices['name'].str.lower() == index).idxmax(), 'id'] - name = indices.loc[(indices['name'].str.lower() == index).idxmax(), 'name'] + full_name = indices.loc[(indices['name'].apply(unidecode).str.lower() == index).idxmax(), 'full_name'] + id_ = indices.loc[(indices['name'].apply(unidecode).str.lower() == index).idxmax(), 'id'] + name = indices.loc[(indices['name'].apply(unidecode).str.lower() == index).idxmax(), 'name'] - index_currency = indices.loc[(indices['name'].str.lower() == index).idxmax(), 'currency'] + index_currency = indices.loc[(indices['name'].apply(unidecode).str.lower() == index).idxmax(), 'currency'] header = full_name + ' Historical Data' @@ -509,14 +509,14 @@ def get_index_historical_data(index, country, from_date, to_date, as_json=False, index = unidecode(index.strip().lower()) - if index not in list(indices['name'].str.lower()): + if index not in list(indices['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0045: index " + index + " not found, check if it is correct.") - full_name = indices.loc[(indices['name'].str.lower() == index).idxmax(), 'full_name'] - id_ = indices.loc[(indices['name'].str.lower() == index).idxmax(), 'id'] - name = indices.loc[(indices['name'].str.lower() == index).idxmax(), 'name'] + full_name = indices.loc[(indices['name'].apply(unidecode).str.lower() == index).idxmax(), 'full_name'] + id_ = indices.loc[(indices['name'].apply(unidecode).str.lower() == index).idxmax(), 'id'] + name = indices.loc[(indices['name'].apply(unidecode).str.lower() == index).idxmax(), 'name'] - index_currency = indices.loc[(indices['name'].str.lower() == index).idxmax(), 'currency'] + index_currency = indices.loc[(indices['name'].apply(unidecode).str.lower() == index).idxmax(), 'currency'] final = list() @@ -692,11 +692,11 @@ def get_index_information(index, country, as_json=False): index = unidecode(index.strip().lower()) - if index not in list(indices['name'].str.lower()): + if index not in list(indices['name'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0045: index " + index + " not found, check if it is correct.") - name = indices.loc[(indices['name'].str.lower() == index).idxmax(), 'name'] - tag = indices.loc[(indices['name'].str.lower() == index).idxmax(), 'tag'] + name = indices.loc[(indices['name'].apply(unidecode).str.lower() == index).idxmax(), 'name'] + tag = indices.loc[(indices['name'].apply(unidecode).str.lower() == index).idxmax(), 'tag'] url = "https://www.investing.com/indices/" + tag diff --git a/investpy/stocks.py b/investpy/stocks.py index e754387a..f1c6c785 100644 --- a/investpy/stocks.py +++ b/investpy/stocks.py @@ -261,14 +261,14 @@ def get_stock_recent_data(stock, country, as_json=False, order='ascending', inte stock = unidecode(stock.strip().lower()) - if stock not in list(stocks['symbol'].str.lower()): + if stock not in list(stocks['symbol'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0018: stock " + stock + " not found, check if it is correct.") - symbol = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'symbol'] - id_ = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'id'] - name = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'name'] + symbol = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'symbol'] + id_ = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'id'] + name = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'name'] - stock_currency = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'currency'] + stock_currency = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'currency'] header = symbol + ' Historical Data' @@ -515,14 +515,14 @@ def get_stock_historical_data(stock, country, from_date, to_date, as_json=False, stock = unidecode(stock.strip().lower()) - if stock not in list(stocks['symbol'].str.lower()): + if stock not in list(stocks['symbol'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0018: stock " + stock + " not found, check if it is correct.") - symbol = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'symbol'] - id_ = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'id'] - name = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'name'] + symbol = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'symbol'] + id_ = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'id'] + name = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'name'] - stock_currency = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'currency'] + stock_currency = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'currency'] final = list() @@ -726,7 +726,7 @@ def get_stock_company_profile(stock, country='spain', language='english'): stock = unidecode(stock.strip().lower()) - if stock not in list(stocks['symbol'].str.lower()): + if stock not in list(stocks['symbol'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0018: stock " + stock + " not found, check if it is correct.") company_profile = { @@ -735,7 +735,7 @@ def get_stock_company_profile(stock, country='spain', language='english'): } if selected_source == 'Bolsa de Madrid': - isin = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'isin'] + isin = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'isin'] url = "http://www.bolsamadrid.es/esp/aspx/Empresas/FichaValor.aspx?ISIN=" + isin @@ -771,7 +771,7 @@ def get_stock_company_profile(stock, country='spain', language='english'): return company_profile elif selected_source == 'Investing': - tag = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'tag'] + tag = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'tag'] url = "https://www.investing.com/equities/" + tag + "-company-profile" @@ -858,10 +858,10 @@ def get_stock_dividends(stock, country): stock = unidecode(stock.strip().lower()) - if stock not in list(stocks['symbol'].str.lower()): + if stock not in list(stocks['symbol'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0018: stock " + stock + " not found, check if it is correct.") - tag_ = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'tag'] + tag_ = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'tag'] headers = { "User-Agent": random_user_agent(), @@ -1077,11 +1077,11 @@ def get_stock_information(stock, country, as_json=False): stock = unidecode(stock.strip().lower()) - if stock not in list(stocks['symbol'].str.lower()): + if stock not in list(stocks['symbol'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0018: stock " + stock + " not found, check if it is correct.") - tag = stocks.loc[(stocks['symbol'].str.lower() == stock.lower()).idxmax(), 'tag'] - stock = stocks.loc[(stocks['symbol'].str.lower() == stock.lower()).idxmax(), 'symbol'] + tag = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock.lower()).idxmax(), 'tag'] + stock = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock.lower()).idxmax(), 'symbol'] url = f"https://www.investing.com/equities/{tag}" @@ -1400,10 +1400,10 @@ def get_stock_financial_summary(stock, country, summary_type='income_statement', stock = unidecode(stock.strip().lower()) - if stock not in list(stocks['symbol'].str.lower()): + if stock not in list(stocks['symbol'].apply(unidecode).str.lower()): raise RuntimeError("ERR#0018: stock " + stock + " not found, check if it is correct.") - id_ = stocks.loc[(stocks['symbol'].str.lower() == stock).idxmax(), 'id'] + id_ = stocks.loc[(stocks['symbol'].apply(unidecode).str.lower() == stock).idxmax(), 'id'] headers = { "User-Agent": random_user_agent(), diff --git a/investpy/technical.py b/investpy/technical.py index 6cd08c5d..9b9e0fa9 100644 --- a/investpy/technical.py +++ b/investpy/technical.py @@ -120,10 +120,10 @@ def technical_indicators(name, country, product_type, interval='daily'): name = unidecode(name.lower().strip()) - if name not in list(data[check].str.lower()): + if name not in list(data[check].apply(unidecode).str.lower()): raise ValueError("ERR#0122: introduced name does not exist in the introduced country (if required).") - product_id = data.loc[(data[check].str.lower() == name).idxmax(), 'id'] + product_id = data.loc[(data[check].apply(unidecode).str.lower() == name).idxmax(), 'id'] data_values = { 'pairID': product_id, @@ -270,10 +270,10 @@ def moving_averages(name, country, product_type, interval='daily'): name = unidecode(name.lower().strip()) - if name not in list(data[check].str.lower()): + if name not in list(data[check].apply(unidecode).str.lower()): raise ValueError("ERR#0122: introduced name does not exist in the introduced country (if required).") - product_id = data.loc[(data[check].str.lower() == name).idxmax(), 'id'] + product_id = data.loc[(data[check].apply(unidecode).str.lower() == name).idxmax(), 'id'] data_values = { 'pairID': product_id, @@ -424,10 +424,10 @@ def pivot_points(name, country, product_type, interval='daily'): name = unidecode(name.lower().strip()) - if name not in list(data[check].str.lower()): + if name not in list(data[check].apply(unidecode).str.lower()): raise ValueError("ERR#0122: introduced name does not exist in the introduced country (if required).") - product_id = data.loc[(data[check].str.lower() == name).idxmax(), 'id'] + product_id = data.loc[(data[check].apply(unidecode).str.lower() == name).idxmax(), 'id'] data_values = { 'pairID': product_id, diff --git a/tests/test_investpy.py b/tests/test_investpy.py index 892ea251..04ee8cd3 100644 --- a/tests/test_investpy.py +++ b/tests/test_investpy.py @@ -304,13 +304,13 @@ def test_investpy_funds(): { 'fund': 'bbva multiactivo conservador pp', 'country': 'spain', - 'as_json': True, + 'as_json': False }, { - 'fund': 'bbva multiactivo conservador pp', - 'country': 'spain', - 'as_json': False, - }, + 'fund': 'öhman Global Growth', + 'country': 'sweden', + 'as_json': True + } ] for param in params: