[英]create data frame with key value pair in scala
As I am new to scala need to convert following code in scala which i written in python由于我是 Scala 的新手,因此需要在我用 Python 编写的 Scala 中转换以下代码
Dict={"test1":"date","test2":"string"}
for x in Dict.keys():
column= x
type = Dict[x]
print (column)
print (type)
output输出
test1
date
test2
string
you can use您可以使用
Map(collection of key/value pairs)
Map(键/值对的集合)
in Scala .在Scala 中。 See Scala Maps
查看Scala 地图
val testMap = Map("test1" -> "Date", "test2" -> "String" )
Iterate over Key/Value pairs迭代键/值对
for ((key,value) <- testMap) println(s"key: $value, value: $value\n")
Conversion to DF转换为 DF
val df = testMap.toSeq.toDF("name", "dataType")
df.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.