Spyder Python“当前不支持对象数组”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41494358/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 01:04:28  来源:igfitidea点击:

Spyder Python "object arrays are currently not supported"

pythonanacondaspyder

提问by Honza

I have a problem in Anaconda Spyder (Python).

我在 Anaconda Spyder (Python) 中遇到问题。

Object type array can not be seen under Windows 10 in the variable explorer. If I click on X or Y, I see an error:

在 Windows 10 下的变量资源管理器中无法看到对象类型数组。如果我点击X 或 Y,我会看到一个错误:

object arrays are currently not supported.

当前不支持对象数组。

I have Win 10 Home 64bit (i7-4710HQ) and Python 3.5.2 | Anaconda 4.2.0 (64-bit) [MSC v.1900 64 bit (AMD64)]

我有 Win 10 Home 64bit (i7-4710HQ) 和 Python 3.5.2 | Anaconda 4.2.0(64 位)[MSC v.1900 64 位 (AMD64)]

Screenshot

截屏

采纳答案by Carlos Cordoba

(Spyder developer here) Support for object arrays will be added in Spyder 4, to be released in 2019.

此处Spyder 开发人员)将在 2019 年发布的Spyder 4 中添加对对象数组的支持。

回答by Aviator

A good example is here

一个很好的例子在这里

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
dataset = pd.read_csv('Salary_Data.csv') #in your case right name of your file
X=dataset.iloc[:,:-1].values   #this will convert dataframe to object
df = pd.DataFrame(X)

You can view data in dataframe this converts arrray to dataframe .

您可以查看 dataframe 中的数据,这会将 arrray 转换为 dataframe 。

And the variable explorer accepts the dataframe. The above is correct and checked code

变量资源管理器接受数据帧。以上是正确的检查代码

回答by user10264987

I used the same without dataFrameand .values.
It worked for me.

我在没有dataFrame和的情况下使用了相同的.values
它对我有用。

x = dataset.iloc[:, :-1]
y = dataset.iloc[:,3]

回答by kaushalpranav

Solution: Downgrade the version of spyder to 3.2.0

解决方法:将spyder版本降级到3.2.0

You can do this by going to anaconda-navigator.

你可以通过 anaconda-navigator 来做到这一点。

If you are following the Udemy Course on Machine Learning, probably the instructor is using an older version of spyder and it is working for him. In the newer versions like 3.2.8, it is not working but can be incorporated in the coming versions in the future.

如果您正在学习有关机器学习的 Udemy 课程,则讲师可能使用的是旧版本的 spyder,并且它对他有用。在 3.2.8 等较新的版本中,它不起作用,但可以在将来的版本中合并。

回答by yucer

I have analyzed the code until the pointthat could be failing for you.

我分析的代码,直到可能被失败你。

It seems that array editor of Spyder doesn't support showing arrays of mixed types (object arrays).

Spyder 的数组编辑器似乎不支持显示混合类型的数组(对象数组)。

Here you can see the supported formats.

在这里您可以看到支持的格式

Something was confusing for me the first time that I used it: you receive the same editor when you click on a Dataset that when you click on an array variable.

我第一次使用它时有些困惑:当您单击数据集时,您会收到与单击数组变量时相同的编辑器。

In the case of a variable of type array, you receive an ArrayEditorwidget. I think that call is made here.

对于array类型的变量,您会收到一个ArrayEditor小部件。我认为这个电话是在这里进行的

But in the case of a variable of type DataFrame, you receive a DataFrameEditor. I think that call is made here

但是对于DataFrame类型的变量,您会收到一个DataFrameEditor。我认为这个电话是在这里打的

The problem is that both widgets look more or less the same, so one tend to think that receive the same result in both cases, but the DataFrameEditorallows mixed types and the ArrayEditornot.

问题是两个小部件看起来或多或少相同,因此人们倾向于认为在两种情况下都会收到相同的结果,但DataFrameEditor允许混合类型而ArrayEditor不允许。

You can try to inspect the array variables in the IPython console until the support is finally released in Spyderfor the proper Widgets.

您可以尝试在 IPython 控制台中检查数组变量,直到最终在Spyder 中发布对适当小部件的支持。

回答by gsyal

Use the following code:

使用以下代码:

dataset = pd.read_csv('Data.csv')
X = pd.DataFrame(dataset.iloc[:, :-1].values)

回答by Puru Agarwal

This is because the array has more than one data-type so it can't show an object with more than one datatype because it can't select a single type.. But if it has only one datatype the type is 'float64' so it can be seen.

这是因为数组有不止一种数据类型,所以它不能显示具有多种数据类型的对象,因为它不能选择一种类型。但如果它只有一种数据类型,则类型是“float64”,所以可以被看见。

回答by EqSan

As long as your variables type are not same and in variable explorer you see this as object, it means variable needs to be converted to same type in your case. You can fix it by using fit_transform():

只要您的变量类型不同,并且在变量资源管理器中您将其视为对象,这意味着在您的情况下需要将变量转换为相同的类型。您可以使用 fit_transform() 修复它:

Here is related part of the code for in that tutorial:

这是该教程中代码的相关部分:

from sklearn.preprocessing import LabelEncoder , OneHotEncoder
labelencoder_X_1 = LabelEncoder()
X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])
labelencoder_X_2 = LabelEncoder()
X[:, 2] = labelencoder_X_1.fit_transform(X[:, 2])
onehotencoder = OneHotEncoder(categorical_features = [1])
X = onehotencoder.fit_transform(X).toarray()

回答by Joe Almeida

There are two things you can do to bypass the variable viewer in Spyder. You can either

您可以做两件事来绕过 Spyder 中的变量查看器。你可以

A) use "print (X)" to reveal the contents of X, or

A)使用“打印(X)”来显示X的内容,或

B) Simple use the IPython console by simply typing X and hit return. That too allow you to quickly reveal if the discussed ML functions are doing their job.

B) 只需输入 X 并按回车键即可轻松使用 IPython 控制台。这也可以让您快速了解所讨论的 ML 功能是否正在发挥作用。

回答by Gurbaksh Singh

It is yet not supported by Spyder but you can use IPyhon Console to print those values by directly typing variable name to it.

Spyder 尚不支持它,但您可以使用 IPyhon 控制台通过直接向其键入变量名称来打印这些值。