Skip to content

Instantly share code, notes, and snippets.

@jlggross
Created July 30, 2020 22:17
Show Gist options
  • Save jlggross/4a7ec1046b3061898dca2c11c902f8c2 to your computer and use it in GitHub Desktop.
Save jlggross/4a7ec1046b3061898dca2c11c902f8c2 to your computer and use it in GitHub Desktop.
Creation of DataFrame after scrapping is complete
import pandas as pd
df = pd.DataFrame(columns=["Ação", "Taxa %"])
for i, element in enumerate(elements):
if len(element.text) < 11: # If any li is empty
continue
newElement = {}
newElement["Ação"] = element.text.split("\n")[0]
newElement["Taxa %"] = element.text.split("\n")[1]
df = df.append(newElement, ignore_index=True)
df["Taxa %"] = df["Taxa %"].str.replace(",", ".")
df["Taxa %"] = df["Taxa %"].str.replace("%", "")
df["Taxa %"] = df["Taxa %"].astype('float')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment