简体   繁体   English

使用 Spyder 导入 csv Python

[英]Import csv Python with Spyder

I am trying to import a csv file into Python but it doesn't seem to work unless I use the Import Data icon.我正在尝试将 csv 文件导入 Python,但除非我使用“导入数据”图标,否则它似乎不起作用。

I've never used Python before so apologies is I am doing something obviously wrong.我以前从未使用过 Python,所以很抱歉我做的事情显然是错误的。 I use R and I am trying to replicate the same tasks I do in R in Python.我使用 R 并且我试图在 Python 中复制我在 R 中所做的相同任务。

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:变量资源管理器面板中没有任何显示,我在 IPython 控制台中得到了这个:

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.如果我使用“导入数据”图标并使用向导在预览选项卡上选择 DataFrame,则它工作正常。 The same file imports into R with the same kind of command so I don't know what I am doing wrong?相同的文件使用相同类型的命令导入到 R 中,所以我不知道我做错了什么? Is there any way to see what code was generated by the wizard so I can compare it to mine?有什么方法可以查看向导生成了哪些代码,以便我可以将其与我的进行比较?

原来数据已经导入,只是没有显示在变量资源管理器中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM