Error to excrever data frame in Excel

Asked

Viewed 28 times

0

I’m trying to extract some data and write to an excel file. However, they come with a Shape=(1,209,26) which generates the following error when trying to pass to the . xlsx "Valueerror: Must pass 2-d input. Shape=(1, 209, 26)". How to turn it into a 2d data frame?

import requests
import pandas as pd

url = "https://www.fundsexplorer.com.br/ranking"

header = {
 "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, 
like Gecko) Chrome/50.0.2661.75 Safari/537.36",
 "X-Requested-With": "XMLHttpRequest"
}

r = requests.get(url, headers=header)

dfs = pd.read_html(r.text)
dfs = pd.DataFrame(dfs)
  • Diego, please reread your question and see if it makes any sense. I recommend to go to [help], read the [Ask] guide and analyze how to mount a [mcve].

1 answer

1


pd.read_html(r.text) returns a list with the tables of the page, then you access the tables by the Dice, in your case the table is in the Indice 0

df = pd.read_html(r.text)[0]

df is already a Dataframe, you no longer need to do the last line conversation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.