[Python] Import csv Python with Spyder

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to import a csv file into Python but it doesn't seem to work unless I use the Import Data icon.

    I've never used Python before so apologies is I am doing something obviously wrong. I use R and I am trying to replicate the same tasks I do in R in Python.

    Here is some sample code:

    import pandas as pd
    import os as os

    Main_Path = "C:/Users/fan0ia/Documents/Python_Files"
    Area = "Pricing"
    Project = "Elasticity"
    Path = os.path.join(R_Files, Business_Area, Project)
    os.chdir(Path)

    #Read in the data
    Seasons = pd.read_csv("seasons.csv")
    Dep_Sec_Key = pd.read_csv("DepSecKey.csv")


    These files import without any issues but when I execute the following:

    UOM = pd.read_csv("FINAL_UOM.csv")


    Nothing shows in the variable explorer panel and I get this in the IPython console:

    In [3]: UOM = pd.read_csv("FINAL_UOM.csv")


    If I use the Import Data icon and use the wizard selecting DataFrame on the preview tab it works fine. The same file imports into R with the same kind of command so I don't know what I am doing wrong? Is there any way to see what code was generated by the wizard so I can compare it to mine?

    Continue reading...

Compartilhe esta Página