2
I have a list and need to remove blanks. I am using replace
, but does not take the space from the beginning of the string after the minus sign, only from the end. This space is not a character?
import time
import pandas as pd
import lxml
import html5lib
from bs4 import BeautifulSoup
from pandas import DataFrame
import numpy as np
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
url = "https://www.sunoresearch.com.br/acoes/itsa4/"
option = Options()
option.headless = True
driver = webdriver.Firefox()
driver.get(url)
time.sleep(10)
driver.find_element_by_xpath('//*[@id="demonstratives"]/div[2]/div[1]/div[1]/ng-select/div').click()
driver.find_element_by_xpath('//*[@id="demonstratives"]/div[2]/div[1]/div[1]/ng-select/div/ul/li[2]').click()
driver.find_element_by_xpath('//*[@id="demonstratives"]/div[2]/div[1]/div[2]/ng-select/div').click()
driver.find_element_by_xpath('//*[@id="demonstratives"]/div[2]/div[1]/div[2]/ng-select/div/ul/li[4]').click()
driver.find_element_by_xpath('//*[@id="demonstratives"]/div[2]/div[2]/div/button[2]').click()
element = driver.find_element_by_xpath('//*[@id="demonstratives"]/div[3]/div[2]')
html_content = element.get_attribute('outerHTML')
soup = BeautifulSoup(html_content, 'html.parser')
table = soup.find(name='table')
df_full = pd.read_html(str(table))[0]
pd.set_option('display.max_columns', None)
df_full= df_full.T.shift(-2,axis=0).T
dm=df_full[['Descrição','1T2020', '4T2019','3T2019','2T2019','1T2019']]
df=pd.DataFrame(dm)
df.loc[:,'1T2020']= df['1T2020'].apply(lambda x: str(x).replace(".",""))
df.loc[:,'1T2020']= df['1T2020'].apply(lambda x: str(x).replace(" ",""))
df.loc[:,'1T2020']= df['1T2020'].apply(lambda x: str(x).replace(",","."))
df.loc[:,'1T2020']= df['1T2020'].apply(lambda x: str(x).replace("M",""))
print(df)
driver.quit()
That space after the minus sign should be removed, shouldn’t it? How to remove?
Originally:
How does this print look without the
replaces
?– Vinicius Bussola
Ficaria In line 0: |Net Revenue 1,162.0 M |E ma line 1: |Costs - 773.0 M|
– Frybii