edf.select("x").distinct.show()显示DataFrame x列中显示的不同值edf.
是否有一种有效的方法来显示这些不同值在数据框中出现的次数?(计算每个不同的值)
我正在尝试在多列上应用字符串索引器。这是我的代码
val stringIndexers = Categorical_Model.map { colName =>new StringIndexer().setInputCol(colName).setOutputCol(colName + "_indexed")}
var dfStringIndexed = stringIndexers(0).fit(df3).transform(df3) // 'fit's a model then 'transform's data
for(x<-1 to stringIndexers.length-1)
{dfStringIndexed = stringIndexers(x).fit(dfStringIndexed).transform(dfStringIndexed)
}
dfStringIndexed = dfStringIndexed.drop(Categorical_Model: _*)
Run Code Online (Sandbox Code Playgroud)
Schema 显示所有可空的列都为 false
stringIndexers 数组显示如下
stringIndexers: Array[org.apache.spark.ml.feature.StringIndexer] = Array(strIdx_c53c3bdf464c, strIdx_61e685c520f7, strIdx_d6e59b2fc69d, ......)
dfStringIndexed.show(10)
Run Code Online (Sandbox Code Playgroud)
这会引发以下错误
org.apache.spark.SparkException: Failed to execute user defined function($anonfun$9: (string) => double)
Run Code Online (Sandbox Code Playgroud)
为什么显示打印模式但没有可用数据。
更新:如果我像这样手动循环字符串索引器而不是循环。此代码有效。这很奇怪。
var dfStringIndexed = stringIndexers(0).fit(df3).transform(df3) // 'fit's a model then 'transform's data
dfStringIndexed = stringIndexers(1).fit(dfStringIndexed).transform(dfStringIndexed)
dfStringIndexed = stringIndexers(2).fit(dfStringIndexed).transform(dfStringIndexed)
dfStringIndexed = stringIndexers(3).fit(dfStringIndexed).transform(dfStringIndexed)
dfStringIndexed …Run Code Online (Sandbox Code Playgroud) 刚刚在Ubuntu 14.04上将带有Hadoop 2.6+的预置版Spark 1.6下载到桌面上.
我按照下面的快速启动Spark Link使用的链接导航到火花外壳并启动了火花
./bin/spark-shell
Run Code Online (Sandbox Code Playgroud)
我收到以下错误.我在这里看到了一个与Mac OSX类似的问题.
ashwin@Console:~/Desktop/spark-1.6.0-bin-hadoop2.6$ ./bin/spark-shell
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Using Spark's repl log4j profile: org/apache/spark/log4j-defaults-repl.properties
To adjust logging level use sc.setLogLevel("INFO")
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 1.6.0
/_/
Using Scala version 2.10.5 (OpenJDK 64-Bit Server VM, …Run Code Online (Sandbox Code Playgroud) df1.printSchema() 打印出他们拥有的列名和数据类型.
df1.drop($"colName") 将按名称删除列.
有没有办法让这个命令改为按数据类型删除?
Spark 笔记本安装后运行基本 df.show()
在 Spark-notebook 上运行 scala - Spark 代码时出现以下错误。知道这种情况何时发生以及如何避免吗?
[org.apache.spark.repl.ExecutorClassLoader] Failed to check existence of class org.apache.spark.sql.catalyst.expressions.Object on REPL class server at spark://192.168.10.194:50935/classes
[org.apache.spark.util.Utils] Aborting task
[org.apache.spark.repl.ExecutorClassLoader] Failed to check existence of class org on REPL class server at spark://192.168.10.194:50935/classes
[org.apache.spark.util.Utils] Aborting task
[org.apache.spark.repl.ExecutorClassLoader] Failed to check existence of class
Run Code Online (Sandbox Code Playgroud) 我在Windows 10上的0.81 Apache Zeppelin上解压缩了完整版,然后导航到C:\ Zeppelin \ bin并输入zeppelin.cmd
只是重复C:\ Zeppelin \ bin“之后,我没有任何输出。而且我可以在文件夹的dir / p中清楚地看到zeppelin.cmd
我该如何调试
这是我想要实现的代码。我收到过载错误。有办法解决吗?
import scala.math._
dF = dF.withColumn("col2",(8.333*exp($"col1")))
error: type mismatch;
found : org.apache.spark.sql.ColumnName
required: Double
Run Code Online (Sandbox Code Playgroud)
如何执行这样的指数运算?
我正在尝试编写代码以将日期时间列 date 和 last_updated_date 转换为“mm-dd-yyyy”格式以显示。我该怎么做呢 ?
import org.joda.time._
import scala.tools._
import org.joda.time.format.DateTimeFormat._
import java.text.SimpleDateFormat
import org.apache.spark.sql.functions.{unix_timestamp, to_date}
root
|-- date: double (nullable = false)
|-- last_updated_date: double (nullable = false)
|-- Percent_Used: double (nullable = false)
+------------+---------------------+------------+
| date| last_updated_date|Percent_Used|
+------------+---------------------+------------+
| 1.453923E12| 1.47080394E12| 1.948327124|
|1.4539233E12| 1.47080394E12| 2.019636442|
|1.4539236E12| 1.47080394E12| 1.995299371|
+------------+---------------------+------------+
Run Code Online (Sandbox Code Playgroud)