1. 读取csv文件变成DataFrame
val data = spark.read.csv("/data/session01.csv")
2.查看df每一列类型
data.dtypes
3.查看df数据
data.show()
def show(numRows: Int, truncate: Int, vertical: Boolean): Unit
参考:http://spark.apache.org/docs/2.3.1/api/scala/index.html#org.apache.spark.sql.Dataset
vertical true和false的区别: 表格格式的问题
原数据:
year month AVG('Adj Close) MAX('Adj Close)
1980 12 0.503218 0.595103
1981 01 0.523289 0.570307
1982 02 0.436504 0.475256
1983 03 0.410516 0.442194
1984 04 0.450090 0.483521
data.show(3, false)
结果:
-RECORD 0-------------------
year | 1980
month | 12
AVG('Adj Close) | 0.503218
AVG('Adj Close) | 0.595103
-RECORD 1-------------------
year | 1981
month | 01
AVG('Adj Close) | 0.523289
AVG('Adj Close) | 0.570307
4. 显示表头(第一行)
data.head()
来源:https://blog.csdn.net/bowenlaw/article/details/99583921