[Python] Re index a list of values in a DataFrame [duplicate]

Discussão em 'Python' iniciado por Stack, Janeiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm doing an ETL process for a DataFrame. The original table had NaN values, duplicates and more things that I drop. But now the "old index" show gaps between the values, for example from the index number 8 to index number 10. So I tried set_index, reindex, len(range(df.index)) for set up the true value of the index but I can't.

    from datetime import datetime, timedelta
    import pandas as pd
    import requests
    from bs4 import BeautifulSoup
    import numpy as np

    url = "https://www.myfxbook.com/forex-economic-calendar"
    codificacion='utf-8'

    response = requests.get(url)
    response.encoding = codificacion
    soup = BeautifulSoup(response.text, 'html.parser')

    tablas = pd.read_html(str(soup), encoding=codificacion)
    tabla = tablas[0]
    # tabla
    tabla.rename(columns={'Unnamed: 3':'Símbolo'}, inplace=True)

    tabla.drop(tabla['Unnamed: 2'].dropna().index, inplace=True)

    tabla.drop(columns=['All None', 'Unnamed: 2'], inplace=True) #para poner otros datos solo se pone columns=['','',''...]

    tabla.drop(tabla[tabla['Impact'] == 'Low'].index, inplace=True)

    help(pd.RangeIndex)


    Additionally, I'm new in this of programming, Do your consider that is better read the page of duoumentation, use the command of help for specific cases (i think that is lot more information in this way) or look in foros por solutions of community? I'm writing here because I want force me to not use chatgpt every time that I'm lock, but that is actually good?

    Continue reading...

Compartilhe esta Página