dataframe 怎么转str_老师,怎么将DataFrame从String类型转成Int类型?

这篇博客探讨了如何将使用Spark读取的CSV文件中String类型的DataFrame数据转换为Int类型。通过示例展示了DataFrame的schema,其中所有列都是String类型,需要转换以便进行数值操作。
摘要由CSDN通过智能技术生成

老师,我读取了一个csv文件var data = spark.read.option("header", "true").format("csv").load("D:\\train.csv")

但是读进来以后数据是String类型的,怎么将数据变成Int类型

printSchema是这样的root

|-- label: string (nullable = true)

|-- pixel0: string (nullable = true)

|-- pixel1: string (nullable = true)

|-- pixel2: string (nullable = true)

|-- pixel3: string (nullable = true)

|-- pixel4: string (nullable = true)

|-- pixel5: string (nullable = true)

|-- pixel6: string (nullable = true)

|-- pixel7: string (nullable = true)

|-- pixel8: string (nullable = true)

|-- pixel9: string (nullable = true)

|-- pixel10: string (nullable = true)

|-- pixel11: string (nullable = true)

|-- pixel12: string (nullable = true)

|-- pixel13: string (nullable = 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值