将 csv 文件加载到 Pandas 数据框中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41730514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Load a csv file into pandas dataframe
提问by Haunchmeat
First question: please be kind.
第一个问题:请善待。
I am having trouble loading a CSV file into a DataFrame on Spyder, using iPython. When I load an XLS file, it seems to have no problem and populates the new DataFrame variable into the variable explorer.
我在使用 iPython 将 CSV 文件加载到 Spyder 上的 DataFrame 时遇到问题。当我加载一个 XLS 文件时,它似乎没有问题并将新的 DataFrame 变量填充到变量资源管理器中。
For example:
例如:
import pandas as pd
energy = pd.read_excel('file.xls', skiprows=17)
The above returns a DataFrame, named energy, populated in the variable explorer (i.e. I can actually see the DataFrame).
以上返回了一个名为energy 的DataFrame,填充在变量资源管理器中(即我实际上可以看到DataFrame)。
However, when I try to load in a CSV file using the same method, it seems to read in the file, however it does not populate the variable explorer.
但是,当我尝试使用相同的方法加载 CSV 文件时,它似乎读入了文件,但它不会填充变量资源管理器。
For example:
例如:
import pandas as pd
GDP = pd.read_csv('file.csv')
When I run the above line, I don't get an error message, but the new DataFrame, GDP
, does not populate the variable explorer. If I print GDP
I get the values (268 rows x 60 columns). Am I not saving the new DataFrame correctly as a variable?
当我运行上面的行时,我没有收到错误消息,但新的 DataFrameGDP
不会填充变量资源管理器。如果我打印,GDP
我会得到值(268 行 x 60 列)。我没有将新的 DataFrame 正确保存为变量吗?
Thanks!
谢谢!
采纳答案by DYZ
The problem is not with the variable, but with the way Variable Explorer filters what it shows. Go to "Tools/Preferences", select "Variable explorer", and uncheck option "Exclude all-uppercase references".
问题不在于变量,而在于变量资源管理器过滤它显示的内容的方式。转到“工具/首选项”,选择“变量资源管理器”,然后取消选中“排除所有大写引用”选项。