小编Sah*_*hil的帖子

我在 Spark 中创建简单 RDD 时遇到错误

我正在使用 Jupyter Notebook,刚刚开始学习 Apache Spark,但在创建简单的 RDD 时出现错误:

sc.parallelize([2, 3, 4]).count()
Run Code Online (Sandbox Code Playgroud)

错误是:parallelize() missing 1 required positional argument: 'c' 这种情况发生在每种情况下,就像我尝试一样textFile(""),我发现位置参数丢失了。我有sparkcontext as sc,有人可以帮我解决这个问题吗?

python apache-spark rdd

9
推荐指数
2
解决办法
1万
查看次数

在 scikitlearn 中为系列使用 LabelEncoder

我在数据集中有一列具有分类值,我想将它们转换为数值。我正在尝试使用 LabelEncoder,但这样做时出错。

from sklearn.preprocessing import LabelEncoder
m = hsp_train["Alley"]
m_enc = LabelEncoder()
j = m_enc.fit_transform(m)
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

不可排序的类型:float() > str()

列中的系列有 3 个值。我希望它们分别为 0、1、2,但我收到了那个错误。

我也试过这个:

l = hsp_train["Alley"]
l_enc = pd.factorize(l)
hsp_train["Alley"] = l_enc[0]
Run Code Online (Sandbox Code Playgroud)

但这给了我值 -1, 1, 2. 我不想要它从 1 开始。

python machine-learning pandas scikit-learn

4
推荐指数
1
解决办法
1859
查看次数

比较两个列表并在python中获取一个新列表

我有一个列表 - 一个列和一个列 - b.

a = [2, 4, 1, 1, 6, 1, 1, 3, 5, 1]
b = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
Run Code Online (Sandbox Code Playgroud)

我想从列表"b"中获取列,当与列表"a"进行比较时,列的值为1.

我希望输出为:

c = ["C", "D", "F", "G", "J"]
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

python list

1
推荐指数
1
解决办法
80
查看次数

从数据框中的列中选择特定值

我有一个只有两列的数据集.我想根据一栏中的某些条件从中提取一小部分.将此视为我的数据集.

A    B
1    10
1    9
2    11
3    12
3    11
4    9
Run Code Online (Sandbox Code Playgroud)

假设我只想提取那些B值在10-12之间的行.所以我得到一个新的数据集:

A    B
1    10
2    11
3    12
3    11
Run Code Online (Sandbox Code Playgroud)

我尝试使用df.loc [df ["B"] ==范围(10,12)]但它不起作用,有人可以帮我这个吗?

python pandas

1
推荐指数
1
解决办法
144
查看次数

如何使用 Python 在绘图中显示图像?

我导入了 matplotlib.pyplot 和 NumPy

我想将桌面上的图像显示到绘图中,但我得到了一个TypeError.

代码 :

img = (image) ( here do we need to give the location of the file or the file directly)

imshow(img, extent=[-25,25,-25,25], cmap = cm.bone)
colorbar()


Error: TypeError: Image data can not convert to float
Run Code Online (Sandbox Code Playgroud)

我使用 Pycharm 作为我的 ide。

python image matplotlib

0
推荐指数
1
解决办法
1万
查看次数