[Python] Why is RStudio Data Viewer Wrong with Python pd.DF - Snowflake Query

Discussão em 'Python' iniciado por Stack, Fevereiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    At loss why when I look at the data viewer in RStudio it looks like it does in the image below yet when I print the data frame it looks normal. Am I missing something? It works fine in Spyder

    Sample Code


    # pip install `snowflake-connector-python` and `pandas` if not already installed
    import snowflake.connector
    import pandas as pd

    # Establish Snowflake connection
    con = snowflake.connector.connect(
    user="email",
    account="server",
    warehouse="DATA_LAKE_READER",
    database="ENTERPRISE",
    authenticator="externalbrowser"
    )

    # Create a cursor and set schema
    cursor = con.cursor()
    cursor.execute("USE SCHEMA CREW_ANALYTICS")

    # Execute query
    query = "SELECT * FROM CT_DEADHEAD LIMIT 10"
    cursor.execute(query)

    # Fetch data and set column names correctly
    columns = [col[0] for col in cursor.description] # Extract column headers

    deadhead_df = pd.DataFrame(cursor.fetchall(), columns=columns) # Assign headers to DataFrame


    # Close cursor and connection
    cursor.close()
    con.close()


    DF Head Output


    >>> print(deadhead_df.head())
    CREW_INDICATOR FLIGHT_NO FLIGHT_DATE ... FILL PAIRING_POSITION PLANNED_POSITION
    0 P NF1 2024-04-18 ... None FO 1FO
    1 P NF1 2024-04-18 ... None CA 1CA
    2 P FAT 2024-04-18 ... None CA 1CA
    3 P ARC 2024-04-04 ... None CA 1CA
    4 P ARC 2024-04-04 ... None FO 1FO

    [5 rows x 45 columns]

    Incorrect RStudio Data Viewer Image


    [​IMG]

    Spyder Viewer


    [​IMG]

    Python Version


    Python 3.12.9

    RStudio Info


    > RStudio.Version()$version
    [1] ‘2024.12.0.467’

    R Version Info


    platform x86_64-w64-mingw32
    arch x86_64
    os mingw32
    crt ucrt
    system x86_64, mingw32
    status
    major 4
    minor 4.2
    year 2024
    month 10
    day 31
    svn rev 87279
    language R
    version.string R version 4.4.2 (2024-10-31 ucrt)
    nickname Pile of Leaves

    Continue reading...

Compartilhe esta Página