这是我的原始Dataframe的一个示例 df
```
+----+
| mix|
+----+
| 1|
| 2|
| cap|
| 3|
| 53|
| 56|
| 98|
| 90|
+----+
列的当前数据类型为 `StringType` 替换值后 `cap` 与 `0` ,可能有两种情况
列没有更多的字符串值,因此所有值现在都是数字
列具有其他字符串值,因此它将保留 `StringType` 如何再次推断数据类型,以便知道替换后的列是否为纯数字 `Numerical` ,确切的数据类型是什么 `Integer` , `Float` , `Double` ```
df.withColumn("mix",when(col("mix") === "cap",0).otherwise(col("mix")))
1条答案
按热度按时间dwbf0jvd1#
如果这对你有帮助,请告诉我。