[Python] Subclassing Pandas DataFrame to obtain column names autocompletion in IDE

Discussão em 'Python' iniciado por Stack, Maio 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am working with Pandas DataFrames in .py files. I would like to have column name autocompletions in VSCode, similar to how it works with .ipynb files.

    I remember reading I could subclass a DataFrame to achieve this. The post showed a code snippet similar to the following:

    class TypedDataFrame(pd.DataFrame):
    day: int
    country: str
    weather: str

    df_path: str = "..."
    df: TypedDataFrame = pd.read_csv(df_path, delimiter=",")

    # now typing "df[" would pull up autocomplete suggestions for the above annotations


    I haven't been able to find the post again. Most of the questions relating this issue date back to 2023 and suggest using Pandera, StaticFrame and other typing libraries, so I think they may be updated now.

    Is there a way to provide type hinting using only Pandas in 2025?

    Continue reading...

Compartilhe esta Página