scala - Comparing 2 Scala 2D arrays: getting error: value sameElements is not a member of (String, String)
问题描述
Hi Im trying the following operation in Scala:
I have 2 dataframes. I want to compare their columns names and then column types. I started by extracting the column names Then I sorted the array and finally printed it
val df1colArr = df1.dtypes
val df2colArr = df2.dtypes
Sorting.quickSort(df1colArr)
Sorting.quickSort(df2colArr)
println(df1colArr.deep.mkString("\n"))
println(df2colArr.deep.mkString("\n"))
The output looks like this:
(age,IntegerType)
(color,StringType)
(dealer_id,StringType)
(first_name,StringType)
(id,IntegerType)
(last_name,StringType)
(loyalty_score,StringType)
(model,StringType)
(purchase_date,TimestampType)
(purchase_price,StringType)
(rank_dr,IntegerType)
(service_date,TimestampType)
(vin_num,StringType)
(age,IntegerType)
(color,StringType)
(dealer_id,StringType)
(first_name,StringType)
(id,IntegerType)
(last_name,StringType)
(loyalty_score,IntegerType)
(model,StringType)
(purchase_date,TimestampType)
(purchase_price,StringType)
(rank_dr,IntegerType)
(repeat_likely,IntegerType)
(service_date,TimestampType)
(vin_num,StringType)
Next I have a simple utility to compare 2 arrays above based on their value at index 0:
val col_similar: ( Array[(String,String)], Array[(String, String)] )=> String
= (x,y) => {if (x(0).sameElements(y(0))) "similar" else "different"}
when I run the above code. I get the following error:
Error:(59, 105) value sameElements is not a member of (String, String)
val col_similar: ( Array[(String,String)], Array[(String, String)] ) => String
= (x,y) => {if (x(0).sameElements(y(0))) "similar" else "different"}
Please help me understand why this code wont work.... Thanks so much
解决方案
x(0)
是一对字符串。如果您想比较成对的数组x
和y
,请执行以下操作:
if (x sameElements y) ... else ...
顺便说一句,我怀疑这种方法是否会扩展到实际的数据集——将整个数据帧收集到主节点通常是一个坏主意。也许你可以在这里找到一些更好的想法。
推荐阅读
- mongodb - 为 BI 安装和运行 MongoDB 连接器
- excel - 如何在考虑 Null 值的情况下将结果从 ORACLE SQL Developer 复制并粘贴到 Excel?
- javascript - 如何使 Electron 欢迎屏幕在会话开始时停止显示?
- python - 将文件放在与 Jupyter 笔记本相同的目录中
- javascript - 无论如何要从 URL.createObjectURL 更改 blob 的路径
- c - 在C中多次使用随机数函数时生成相同的随机数
- python - 在python中加密然后解密相同的字符串
- isis - 侧边栏宽度太短,无法显示 datetimepicker
- javascript - 在 React 中输入一个字符后输入失去焦点
- google-cloud-platform - 当 gcloud compute ssh 命令卡住/挂起而没有错误消息时,如何解决无法 ssh 进入谷歌云实例的问题?